959: Retrieve current working directory from workspace r=matklad a=LDSpits

This PR improves the way the language client retrieves the current working directory by using the VSCode workspace API to get the path to the currently open directory.

If we find more than one directory we show a warning that "multi root workspaces are not supported yet" and pick the root path.

Any feedback is appreciated 😄

fixes #945

Co-authored-by: Lucas Spits <spits.lucas@gmail.com>
This commit is contained in:
bors[bot] 2019-03-12 10:23:47 +00:00
commit 97a87bf3a6

View file

@ -1,6 +1,6 @@
import * as lc from 'vscode-languageclient';
import { window } from 'vscode';
import { window, workspace } from 'vscode';
import { Config } from './config';
import { Highlighter } from './highlighting';
@ -12,9 +12,23 @@ export class Server {
public static start(
notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>
) {
// '.' Is the fallback if no folder is open
// TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file.
let folder: string = '.';
if (workspace.workspaceFolders !== undefined) {
folder = workspace.workspaceFolders[0].uri.fsPath.toString();
if (workspace.workspaceFolders.length > 1) {
// Tell the user that we do not support multi-root workspaces yet
window.showWarningMessage(
'Multi-root workspaces are not currently supported'
);
}
}
const run: lc.Executable = {
command: this.config.raLspServerPath,
options: { cwd: '.' }
options: { cwd: folder }
};
const serverOptions: lc.ServerOptions = {
run,