Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

[WIP] Fix #2690 - Allow extra args to pass directly to Neovim #2694

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion browser/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ export const start = async (args: string[]): Promise<void> => {
const cssPromise = import("./CSS")
const completionProvidersPromise = import("./Services/Completion/CompletionProviders")

const parsedArgs = minimist(args, { string: "_" })
const parsedArgs = minimist(args, { "--": true, string: "_" })
const currentWorkingDirectory = process.cwd()
const normalizedFiles = parsedArgs._.map(
arg => (path.isAbsolute(arg) ? arg : path.join(currentWorkingDirectory, arg)),
)

const additionalArgs = parsedArgs["--"] || []

const filesToOpen = normalizedFiles.filter(f => {
if (fs.existsSync(f)) {
return fs.statSync(f).isFile()
Expand Down Expand Up @@ -293,6 +295,7 @@ export const start = async (args: string[]): Promise<void> => {
const initializeAllEditors = async () => {
await startEditors(
filesToOpen,
additionalArgs,
Colors.getInstance(),
CompletionProviders.getInstance(),
configuration,
Expand Down
10 changes: 9 additions & 1 deletion browser/src/Editor/NeovimEditor/NeovimEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -998,15 +998,23 @@ export class NeovimEditor extends Editor implements Oni.Editor {

public async init(
filesToOpen: string[],
additionalArgs?: string[],
startOptions?: Partial<INeovimStartOptions>,
): Promise<void> {
Log.info("[NeovimEditor::init] Called with filesToOpen: " + filesToOpen)
Log.info(
"[NeovimEditor::init] Called with filesToOpen: " +
filesToOpen +
" and args: " +
additionalArgs,
)
additionalArgs = additionalArgs || []
const defaultOptions: INeovimStartOptions = {
runtimePaths: this._pluginManager.getAllRuntimePaths(),
transport: this._configuration.getValue("experimental.neovim.transport"),
neovimPath: this._configuration.getValue("debug.neovimPath"),
loadInitVim: this._configuration.getValue("oni.loadInitVim"),
useDefaultConfig: this._configuration.getValue("oni.useDefaultConfig"),
additionalArgs: additionalArgs,
}

const combinedOptions = {
Expand Down
4 changes: 2 additions & 2 deletions browser/src/Editor/OniEditor/OniEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ export class OniEditor extends Utility.Disposable implements Oni.Editor {
this._neovimEditor.bufferDelete(bufferId)
}

public async init(filesToOpen: string[]): Promise<void> {
public async init(filesToOpen: string[], additionalArgs?: string[]): Promise<void> {
Log.info("[OniEditor::init] Called with filesToOpen: " + filesToOpen)

return this._neovimEditor.init(filesToOpen)
return this._neovimEditor.init(filesToOpen, additionalArgs)
}

public async input(key: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class TutorialBufferLayer implements Oni.BufferLayer {
alert("quit!")
})

this._initPromise = this._editor.init([], {
this._initPromise = this._editor.init([], [], {
loadInitVim: false,
})

Expand Down
24 changes: 15 additions & 9 deletions browser/src/neovim/NeovimProcessSpawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ export interface INeovimStartOptions {
// Explicitly specify the path to Neovim. If not specified,
// the default path will be used.
neovimPath?: string

// Additional arguments to pass directly to Neovim
additionalArgs: string[]
}

const DefaultStartOptions: INeovimStartOptions = {
runtimePaths: [],
transport: "stdio",
loadInitVim: true,
useDefaultConfig: true,
additionalArgs: [],
}

const getSessionFromProcess = async (
Expand Down Expand Up @@ -122,15 +126,17 @@ export const startNeovim = async (
initVimArg = ["-u", loadInitVimConfigOption]
}

const argsToPass = initVimArg.concat([
"--cmd",
`let &rtp.=',${joinedRuntimePaths}'`,
"--cmd",
"let g:gui_oni = 1",
"-N",
"--embed",
"--",
])
const argsToPass = initVimArg
.concat([
"--cmd",
`let &rtp.=',${joinedRuntimePaths}'`,
"--cmd",
"let g:gui_oni = 1",
"-N",
"--embed",
])
.concat(options.additionalArgs)
.concat(["--"])

Log.verbose(
"[NeovimProcessSpawner::startNeovim] Sending these args to Neovim: " +
Expand Down
1 change: 1 addition & 0 deletions browser/src/neovim/SharedNeovimInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class SharedNeovimInstance implements SharedNeovimInstance {

public async start(): Promise<void> {
const startOptions: INeovimStartOptions = {
additionalArgs: [],
runtimePaths: this._pluginManager.getAllRuntimePaths(),
loadInitVim: false,
useDefaultConfig: true,
Expand Down
5 changes: 3 additions & 2 deletions browser/src/startEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { windowManager } from "./Services/WindowManager"
import { Workspace } from "./Services/Workspace"

export const startEditors = async (
args: any,
filesToOpen: string[],
additionalArgs: string[],
colors: Colors,
completionProviders: CompletionProviders,
configuration: Configuration,
Expand Down Expand Up @@ -52,5 +53,5 @@ export const startEditors = async (
)
windowManager.createSplit("horizontal", editor)

await editor.init(args)
await editor.init(filesToOpen, additionalArgs)
}