From d11bb41d337dca67b6b3a4e02df74c844f0f1506 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 4 Oct 2022 20:27:26 +0200 Subject: [PATCH] Allow opening files at a specific line and column (fixes #5619) --- src/node/main.ts | 9 +++++---- src/node/util.ts | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/node/main.ts b/src/node/main.ts index 00b4bda1..cf589952 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -9,7 +9,7 @@ import { AuthType, DefaultedArgs, Feature, SpawnCodeCli, toCodeArgs, UserProvide import { coderCloudBind } from "./coder_cloud" import { commit, version } from "./constants" import { register } from "./routes" -import { humanPath, isFile, loadAMDModule, open } from "./util" +import { humanPath, isDirectory, loadAMDModule, open } from "./util" /** * Return true if the user passed an extension-related VS Code flag. @@ -69,14 +69,15 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st fileURIs: [], forceReuseWindow: args["reuse-window"], forceNewWindow: args["new-window"], + gotoLineMode: true, } const paths = args._ || [] for (let i = 0; i < paths.length; i++) { const fp = path.resolve(paths[i]) - if (await isFile(fp)) { - pipeArgs.fileURIs.push(fp) - } else { + if (await isDirectory(fp)) { pipeArgs.folderURIs.push(fp) + } else { + pipeArgs.fileURIs.push(fp) } } if (pipeArgs.forceNewWindow && pipeArgs.fileURIs.length > 0) { diff --git a/src/node/util.ts b/src/node/util.ts index 140431cc..698fe604 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -482,6 +482,15 @@ export const isFile = async (path: string): Promise => { } } +export const isDirectory = async (path: string): Promise => { + try { + const stat = await fs.stat(path) + return stat.isDirectory() + } catch (error) { + return false + } +} + /** * Escapes any HTML string special characters, like &, <, >, ", and '. *