Skip to content
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: 3 additions & 2 deletions src/node/vscodeSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { errorHandler } from "./routes/errors"
import { canConnect } from "./util"

export interface EditorSessionEntry {
workspace: {
// Not set for a window that has no folder open.
workspace?: {
id: string
folders: {
uri: {
Expand Down Expand Up @@ -98,7 +99,7 @@ export class EditorSessionManager {
if (matchCheckResults.has(entry.socketPath)) {
return matchCheckResults.get(entry.socketPath)!
}
const result = entry.workspace.folders.some((folder) => filePath.startsWith(folder.uri.path + path.sep))
const result = entry.workspace?.folders.some((folder) => filePath.startsWith(folder.uri.path + path.sep)) ?? false
matchCheckResults.set(entry.socketPath, result)
return result
}
Expand Down
36 changes: 36 additions & 0 deletions test/unit/node/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,42 @@ describe("cli", () => {
vscodeSockets.close()
})

it("should use existing if a window with no folder is also open", async () => {
const sessionSocket = path.join(tmpDirPath, "session-socket")
const server = await makeEditorSessionManagerServer(sessionSocket, new EditorSessionManager())

const client = new EditorSessionManagerClient(sessionSocket)
const socketPath = path.join(tmpDirPath, "socket")
await client.addSession({
entry: {
workspace: {
id: "aaa",
folders: [
{
uri: {
path: "/aaa",
},
},
],
},
socketPath,
},
})
// Code sends no workspace for a window with no folder open.
await client.addSession({
entry: {
socketPath: path.join(tmpDirPath, "socket-no-folder"),
},
})
const vscodeSockets = listenOn(socketPath)

const args: UserProvidedArgs = { "reuse-window": true, _: ["/aaa/file"] }
await expect(shouldOpenInExistingInstance(args, sessionSocket)).resolves.toStrictEqual(socketPath)

server.close()
vscodeSockets.close()
})

it("should prefer matching sessions for only the first path", async () => {
const sessionSocket = path.join(tmpDirPath, "session-socket")
const server = await makeEditorSessionManagerServer(sessionSocket, new EditorSessionManager())
Expand Down
25 changes: 25 additions & 0 deletions test/unit/node/vscodeSocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,31 @@ describe("EditorSessionManager", () => {
`${tmpDirPath}/vscode-ipc-aaa.sock`,
])
})
it("should not fail on a window with no folder open", async () => {
const manager = new EditorSessionManager()
manager.addSession({
workspace: {
id: "aaa",
folders: [
{
uri: {
path: "/aaa",
},
},
],
},
socketPath: `${tmpDirPath}/vscode-ipc-aaa.sock`,
})
// Code sends no workspace for a window with no folder open.
manager.addSession({
socketPath: `${tmpDirPath}/vscode-ipc-empty.sock`,
})
const entries = manager.getCandidatesForFile("/bbb/some-file:1:1")
expect(entries.map((x) => x.socketPath)).toEqual([
`${tmpDirPath}/vscode-ipc-empty.sock`,
`${tmpDirPath}/vscode-ipc-aaa.sock`,
])
})
})

describe("getConnectedSocketPath", () => {
Expand Down
Loading