Skip to content

Commit

Permalink
Fix multifolder support
Browse files Browse the repository at this point in the history
  • Loading branch information
appilon committed Aug 14, 2020
1 parent 4eee81a commit 32c6470
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function activate(context: vscode.ExtensionContext) {
if (event.removed.length > 0) {
await stopClients(sortedWorkspaceFolders(event.removed));
}
if (event.removed.length > 0) {
if (event.added.length > 0) {
await startClients(sortedWorkspaceFolders(event.added));
}
}
Expand All @@ -93,9 +93,13 @@ async function startClients(folders = sortedWorkspaceFolders()) {
const command = await pathToBinary();
let disposables: vscode.Disposable[] = [];
for (const folder of folders) {
const client = newClient(command, folder);
disposables.push(client.start());
clients.set(folder, client);
if (!clients.has(folder)) {
const client = newClient(command, folder);
disposables.push(client.start());
clients.set(folder, client);
} else {
console.log(`Client for folder: ${folder} already started`);
}
}
return disposables
}
Expand All @@ -118,12 +122,10 @@ function newClient(cmd: string, folder: string) {
run: executable,
debug: executable
};

const f = vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(folder));
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'terraform' }],
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.tf')
},
documentSelector: [{ scheme: 'file', language: 'terraform', pattern: `${f.uri.fsPath}/**/*` }],
workspaceFolder: f,
initializationOptions: initializationOptions,
outputChannel: setup,
revealOutputChannelOn: 4 // hide always
Expand All @@ -145,7 +147,7 @@ async function stopClients(folders = sortedWorkspaceFolders()) {
promises.push(clients.get(folder).stop());
clients.delete(folder);
} else {
console.error(`Attempted to stop a client for folder: ${folder} but no client exists`);
console.log(`Attempted to stop a client for folder: ${folder} but no client exists`);
}
}
return Promise.all(promises);
Expand Down

0 comments on commit 32c6470

Please sign in to comment.