Skip to content

Commit 47cf51b

Browse files
committed
Hide code lens functionality behind a setting.
1 parent c79a8f9 commit 47cf51b

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

client/src/extension.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ export function activate(context: ExtensionContext) {
240240
// language client, and because of that requires a full restart.
241241
context.subscriptions.push(
242242
workspace.onDidChangeConfiguration(({ affectsConfiguration }) => {
243-
if (affectsConfiguration("rescript.settings.inlayHints")) {
243+
if (
244+
affectsConfiguration("rescript.settings.inlayHints") ||
245+
affectsConfiguration("rescript.settings.codeLens")
246+
) {
244247
commands.executeCommand("rescript-vscode.restart_language_server");
245248
}
246249
})

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@
146146
],
147147
"minimum": 0
148148
},
149+
"rescript.settings.codeLens.enable": {
150+
"type": "boolean",
151+
"default": false,
152+
"description": "Enable (experimental) code lens for function definitions."
153+
},
149154
"rescript.settings.binaryPath": {
150155
"type": ["string", "null"],
151156
"default": null,

server/src/server.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface extensionConfiguration {
3131
enable: boolean;
3232
maxLength: number | null;
3333
};
34+
codeLens: boolean;
3435
binaryPath: string | null;
3536
}
3637
let extensionConfiguration: extensionConfiguration = {
@@ -39,6 +40,7 @@ let extensionConfiguration: extensionConfiguration = {
3940
enable: false,
4041
maxLength: 25
4142
},
43+
codeLens: false,
4244
binaryPath: null,
4345
};
4446
let pullConfigurationPeriodically: NodeJS.Timeout | null = null;
@@ -230,6 +232,9 @@ let compilerLogsWatcher = chokidar
230232
if (extensionConfiguration.inlayHints.enable === true) {
231233
sendInlayHintsRefresh();
232234
}
235+
if (extensionConfiguration.codeLens === true) {
236+
sendCodeLensRefresh();
237+
}
233238
});
234239
let stopWatchingCompilerLog = () => {
235240
// TODO: cleanup of compilerLogs?
@@ -424,6 +429,15 @@ function codeLens(msg: p.RequestMessage) {
424429
return response;
425430
}
426431

432+
function sendCodeLensRefresh() {
433+
let request: p.RequestMessage = {
434+
jsonrpc: c.jsonrpcVersion,
435+
method: p.CodeLensRefreshRequest.method,
436+
id: serverSentRequestIdCounter++,
437+
};
438+
send(request);
439+
}
440+
427441
function definition(msg: p.RequestMessage) {
428442
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
429443
let params = msg.params as p.DefinitionParams;
@@ -1014,9 +1028,11 @@ function onMessage(msg: p.Message) {
10141028
full: true,
10151029
},
10161030
inlayHintProvider: extensionConfiguration.inlayHints.enable,
1017-
codeLensProvider: {
1018-
workDoneProgress: false
1019-
},
1031+
codeLensProvider: extensionConfiguration.codeLens
1032+
? {
1033+
workDoneProgress: false,
1034+
}
1035+
: undefined,
10201036
},
10211037
};
10221038
let response: p.ResponseMessage = {

0 commit comments

Comments
 (0)