From 7c1083f83015e39c78e2a652fe02c23f1f85aeed Mon Sep 17 00:00:00 2001 From: Bryan Phelps Date: Tue, 18 Dec 2018 14:03:01 -0800 Subject: [PATCH 1/2] WIP: Plumb through additional arguments --- browser/src/App.ts | 5 ++++- browser/src/Editor/NeovimEditor/NeovimEditor.tsx | 5 ++++- browser/src/Editor/OniEditor/OniEditor.tsx | 4 ++-- .../Learning/Tutorial/TutorialBufferLayer.tsx | 2 +- browser/src/neovim/NeovimProcessSpawner.ts | 12 +++++++++--- browser/src/neovim/SharedNeovimInstance.ts | 1 + browser/src/startEditors.ts | 5 +++-- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/browser/src/App.ts b/browser/src/App.ts index ae1d2e8372..478510cccd 100644 --- a/browser/src/App.ts +++ b/browser/src/App.ts @@ -105,12 +105,14 @@ export const start = async (args: string[]): Promise => { 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() @@ -293,6 +295,7 @@ export const start = async (args: string[]): Promise => { const initializeAllEditors = async () => { await startEditors( filesToOpen, + additionalArgs, Colors.getInstance(), CompletionProviders.getInstance(), configuration, diff --git a/browser/src/Editor/NeovimEditor/NeovimEditor.tsx b/browser/src/Editor/NeovimEditor/NeovimEditor.tsx index a67f0e4a23..e677b624d8 100644 --- a/browser/src/Editor/NeovimEditor/NeovimEditor.tsx +++ b/browser/src/Editor/NeovimEditor/NeovimEditor.tsx @@ -998,15 +998,18 @@ export class NeovimEditor extends Editor implements Oni.Editor { public async init( filesToOpen: string[], + additionalArgs?: string[], startOptions?: Partial, ): Promise { - 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 = { diff --git a/browser/src/Editor/OniEditor/OniEditor.tsx b/browser/src/Editor/OniEditor/OniEditor.tsx index 8694900520..01831b02ce 100644 --- a/browser/src/Editor/OniEditor/OniEditor.tsx +++ b/browser/src/Editor/OniEditor/OniEditor.tsx @@ -331,10 +331,10 @@ export class OniEditor extends Utility.Disposable implements Oni.Editor { this._neovimEditor.bufferDelete(bufferId) } - public async init(filesToOpen: string[]): Promise { + public async init(filesToOpen: string[], additionalArgs?: string[]): Promise { 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 { diff --git a/browser/src/Services/Learning/Tutorial/TutorialBufferLayer.tsx b/browser/src/Services/Learning/Tutorial/TutorialBufferLayer.tsx index 6c56aed169..f90e1ebfba 100644 --- a/browser/src/Services/Learning/Tutorial/TutorialBufferLayer.tsx +++ b/browser/src/Services/Learning/Tutorial/TutorialBufferLayer.tsx @@ -132,7 +132,7 @@ export class TutorialBufferLayer implements Oni.BufferLayer { alert("quit!") }) - this._initPromise = this._editor.init([], { + this._initPromise = this._editor.init([], [], { loadInitVim: false, }) diff --git a/browser/src/neovim/NeovimProcessSpawner.ts b/browser/src/neovim/NeovimProcessSpawner.ts index 97715d6663..eb3bc5983c 100644 --- a/browser/src/neovim/NeovimProcessSpawner.ts +++ b/browser/src/neovim/NeovimProcessSpawner.ts @@ -32,6 +32,9 @@ 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 = { @@ -39,6 +42,7 @@ const DefaultStartOptions: INeovimStartOptions = { transport: "stdio", loadInitVim: true, useDefaultConfig: true, + additionalArgs: [], } const getSessionFromProcess = async ( @@ -122,15 +126,17 @@ export const startNeovim = async ( initVimArg = ["-u", loadInitVimConfigOption] } - const argsToPass = initVimArg.concat([ + 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: " + diff --git a/browser/src/neovim/SharedNeovimInstance.ts b/browser/src/neovim/SharedNeovimInstance.ts index a18cb3f5fa..fd8f88dcfc 100644 --- a/browser/src/neovim/SharedNeovimInstance.ts +++ b/browser/src/neovim/SharedNeovimInstance.ts @@ -167,6 +167,7 @@ class SharedNeovimInstance implements SharedNeovimInstance { public async start(): Promise { const startOptions: INeovimStartOptions = { + additionalArgs: [], runtimePaths: this._pluginManager.getAllRuntimePaths(), loadInitVim: false, useDefaultConfig: true, diff --git a/browser/src/startEditors.ts b/browser/src/startEditors.ts index 69b3c7ee5b..8a8b0b19b7 100644 --- a/browser/src/startEditors.ts +++ b/browser/src/startEditors.ts @@ -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, @@ -52,5 +53,5 @@ export const startEditors = async ( ) windowManager.createSplit("horizontal", editor) - await editor.init(args) + await editor.init(filesToOpen, additionalArgs); } From 495608ea4c1456ff3015e178b765119be3ede2e8 Mon Sep 17 00:00:00 2001 From: Bryan Phelps Date: Tue, 18 Dec 2018 14:03:14 -0800 Subject: [PATCH 2/2] Fix lint issues --- browser/src/App.ts | 2 +- browser/src/Editor/NeovimEditor/NeovimEditor.tsx | 9 +++++++-- browser/src/neovim/NeovimProcessSpawner.ts | 14 +++++++------- browser/src/startEditors.ts | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/browser/src/App.ts b/browser/src/App.ts index 478510cccd..3537ae72df 100644 --- a/browser/src/App.ts +++ b/browser/src/App.ts @@ -111,7 +111,7 @@ export const start = async (args: string[]): Promise => { arg => (path.isAbsolute(arg) ? arg : path.join(currentWorkingDirectory, arg)), ) - const additionalArgs = parsedArgs["--"] || []; + const additionalArgs = parsedArgs["--"] || [] const filesToOpen = normalizedFiles.filter(f => { if (fs.existsSync(f)) { diff --git a/browser/src/Editor/NeovimEditor/NeovimEditor.tsx b/browser/src/Editor/NeovimEditor/NeovimEditor.tsx index e677b624d8..56105da781 100644 --- a/browser/src/Editor/NeovimEditor/NeovimEditor.tsx +++ b/browser/src/Editor/NeovimEditor/NeovimEditor.tsx @@ -1001,8 +1001,13 @@ export class NeovimEditor extends Editor implements Oni.Editor { additionalArgs?: string[], startOptions?: Partial, ): Promise { - Log.info("[NeovimEditor::init] Called with filesToOpen: " + filesToOpen + " and args: " + additionalArgs); - additionalArgs = additionalArgs || []; + 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"), diff --git a/browser/src/neovim/NeovimProcessSpawner.ts b/browser/src/neovim/NeovimProcessSpawner.ts index eb3bc5983c..6034b62b66 100644 --- a/browser/src/neovim/NeovimProcessSpawner.ts +++ b/browser/src/neovim/NeovimProcessSpawner.ts @@ -128,15 +128,15 @@ export const startNeovim = async ( const argsToPass = initVimArg .concat([ - "--cmd", - `let &rtp.=',${joinedRuntimePaths}'`, - "--cmd", - "let g:gui_oni = 1", - "-N", - "--embed", + "--cmd", + `let &rtp.=',${joinedRuntimePaths}'`, + "--cmd", + "let g:gui_oni = 1", + "-N", + "--embed", ]) .concat(options.additionalArgs) - .concat(["--"]); + .concat(["--"]) Log.verbose( "[NeovimProcessSpawner::startNeovim] Sending these args to Neovim: " + diff --git a/browser/src/startEditors.ts b/browser/src/startEditors.ts index 8a8b0b19b7..4ad78dc676 100644 --- a/browser/src/startEditors.ts +++ b/browser/src/startEditors.ts @@ -53,5 +53,5 @@ export const startEditors = async ( ) windowManager.createSplit("horizontal", editor) - await editor.init(filesToOpen, additionalArgs); + await editor.init(filesToOpen, additionalArgs) }