Skip to content

ensure updated config is synced on use of restart command #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2022
Merged
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
84 changes: 38 additions & 46 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,44 @@ let client: LanguageClient;
// });

export function activate(context: ExtensionContext) {
function attachCodeAnalysis(client: LanguageClient) {
function createLanguageClient() {
// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join("server", "out", "server.js")
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions,
},
};

// Options to control the language client
let clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "rescript" }],
// We'll send the initial configuration in here, but this might be
// problematic because every consumer of the LS will need to mimic this.
// We'll leave it like this for now, but might be worth revisiting later on.
initializationOptions: {
extensionConfiguration: workspace.getConfiguration("rescript.settings"),
},
};

const client = new LanguageClient(
"ReScriptLSP",
"ReScript Language Server",
serverOptions,
clientOptions
);

// This sets up a listener that, if we're in code analysis mode, triggers
// code analysis as the LS server reports that ReScript compilation has
// finished. This is needed because code analysis must wait until
Expand All @@ -89,55 +126,10 @@ export function activate(context: ExtensionContext) {
})
);
});
}

/** creates a language client and attaches code analysis */
function createLanguageClient() {
const client = new LanguageClient(
"ReScriptLSP",
"ReScript Language Server",
serverOptions,
clientOptions
);
attachCodeAnalysis(client);
return client;
}

// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join("server", "out", "server.js")
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions,
},
};

// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: "file", language: "rescript" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
// We'll send the initial configuration in here, but this might be
// problematic because every consumer of the LS will need to mimic this.
// We'll leave it like this for now, but might be worth revisiting later on.
initializationOptions: {
extensionConfiguration: workspace.getConfiguration("rescript.settings"),
},
};

// Create the language client and start the client.
client = createLanguageClient();

Expand Down