Skip to content

Commit 566575a

Browse files
StevenLoveHerringtonDarkholme
authored andcommitted
fix: do not automatically start LSP client/server if no sgconfig.yml is found
1 parent 0434655 commit 566575a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/extension/lsp.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ async function testBinaryExist() {
4747
})
4848
}
4949

50+
async function fileExists(pathFromRoot: string): Promise<boolean> {
51+
const workspaceFolders = workspace.workspaceFolders
52+
if (!workspaceFolders) {
53+
return false
54+
}
55+
const uri = Uri.joinPath(workspaceFolders[0].uri, pathFromRoot)
56+
try {
57+
await workspace.fs.stat(uri)
58+
return true
59+
} catch {
60+
return false
61+
}
62+
}
63+
5064
/**
5165
* Set up language server/client
5266
*/
@@ -109,8 +123,11 @@ export async function activateLsp(context: ExtensionContext) {
109123
clientOptions,
110124
)
111125

112-
// Start the client. This will also launch the server
113-
client.start()
126+
// Automatically start the client only if we can find a config file
127+
if (await fileExists('sgconfig.yml')) {
128+
// Start the client. This will also launch the server
129+
client.start()
130+
}
114131
}
115132

116133
async function restart(): Promise<void> {

0 commit comments

Comments
 (0)