Allow opening files at a specific line and column (fixes #5619)

This commit is contained in:
Daniil Gentili 2022-10-04 20:27:26 +02:00
parent 3a9eb312b1
commit d11bb41d33
2 changed files with 14 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import { AuthType, DefaultedArgs, Feature, SpawnCodeCli, toCodeArgs, UserProvide
import { coderCloudBind } from "./coder_cloud" import { coderCloudBind } from "./coder_cloud"
import { commit, version } from "./constants" import { commit, version } from "./constants"
import { register } from "./routes" 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. * 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: [], fileURIs: [],
forceReuseWindow: args["reuse-window"], forceReuseWindow: args["reuse-window"],
forceNewWindow: args["new-window"], forceNewWindow: args["new-window"],
gotoLineMode: true,
} }
const paths = args._ || [] const paths = args._ || []
for (let i = 0; i < paths.length; i++) { for (let i = 0; i < paths.length; i++) {
const fp = path.resolve(paths[i]) const fp = path.resolve(paths[i])
if (await isFile(fp)) { if (await isDirectory(fp)) {
pipeArgs.fileURIs.push(fp)
} else {
pipeArgs.folderURIs.push(fp) pipeArgs.folderURIs.push(fp)
} else {
pipeArgs.fileURIs.push(fp)
} }
} }
if (pipeArgs.forceNewWindow && pipeArgs.fileURIs.length > 0) { if (pipeArgs.forceNewWindow && pipeArgs.fileURIs.length > 0) {

View File

@ -482,6 +482,15 @@ export const isFile = async (path: string): Promise<boolean> => {
} }
} }
export const isDirectory = async (path: string): Promise<boolean> => {
try {
const stat = await fs.stat(path)
return stat.isDirectory()
} catch (error) {
return false
}
}
/** /**
* Escapes any HTML string special characters, like &, <, >, ", and '. * Escapes any HTML string special characters, like &, <, >, ", and '.
* *