Skip to content

Commit 7f79dbc

Browse files
bors[bot]kjeremy
andauthored
Merge #5930
5930: Migrate to the latest Semantic Tokens Proposal for LSP 3.16 r=matklad a=kjeremy This stabilizes call hierarchy and semantic tokens features on the client side and changes the server-side semantic tokens protocol to match the latest proposal for 3.16. The server-side change will break clients depending on the earlier semantic tokens draft. Fixes #4942 Co-authored-by: kjeremy <[email protected]>
2 parents a2e8e51 + 36692bd commit 7f79dbc

File tree

13 files changed

+51
-61
lines changed

13 files changed

+51
-61
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env_logger = { version = "0.7.1", default-features = false }
2121
itertools = "0.9.0"
2222
jod-thread = "0.1.0"
2323
log = "0.4.8"
24-
lsp-types = { version = "0.79.0", features = ["proposed"] }
24+
lsp-types = { version = "0.80.0", features = ["proposed"] }
2525
parking_lot = "0.11.0"
2626
pico-args = "0.3.1"
2727
oorandom = "11.1.2"

crates/rust-analyzer/src/caps.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use lsp_types::{
66
CodeActionProviderCapability, CodeLensOptions, CompletionOptions,
77
DocumentOnTypeFormattingOptions, FoldingRangeProviderCapability, HoverProviderCapability,
88
ImplementationProviderCapability, RenameOptions, RenameProviderCapability, SaveOptions,
9-
SelectionRangeProviderCapability, SemanticTokensDocumentProvider, SemanticTokensLegend,
9+
SelectionRangeProviderCapability, SemanticTokensFullOptions, SemanticTokensLegend,
1010
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
1111
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
1212
WorkDoneProgressOptions,
@@ -76,10 +76,8 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
7676
token_modifiers: semantic_tokens::SUPPORTED_MODIFIERS.to_vec(),
7777
},
7878

79-
document_provider: Some(SemanticTokensDocumentProvider::Edits {
80-
edits: Some(true),
81-
}),
82-
range_provider: Some(true),
79+
full: Some(SemanticTokensFullOptions::Delta { delta: Some(true) }),
80+
range: Some(true),
8381
work_done_progress_options: Default::default(),
8482
}
8583
.into(),

crates/rust-analyzer/src/handlers.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use lsp_types::{
1717
CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
1818
CodeActionKind, CodeLens, Command, CompletionItem, Diagnostic, DocumentFormattingParams,
1919
DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location,
20-
Position, PrepareRenameResponse, Range, RenameParams, SemanticTokensEditResult,
21-
SemanticTokensEditsParams, SemanticTokensParams, SemanticTokensRangeParams,
20+
Position, PrepareRenameResponse, Range, RenameParams, SemanticTokensDeltaParams,
21+
SemanticTokensFullDeltaResult, SemanticTokensParams, SemanticTokensRangeParams,
2222
SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, SymbolTag,
2323
TextDocumentIdentifier, Url, WorkspaceEdit,
2424
};
@@ -1171,11 +1171,11 @@ pub(crate) fn handle_call_hierarchy_outgoing(
11711171
Ok(Some(res))
11721172
}
11731173

1174-
pub(crate) fn handle_semantic_tokens(
1174+
pub(crate) fn handle_semantic_tokens_full(
11751175
snap: GlobalStateSnapshot,
11761176
params: SemanticTokensParams,
11771177
) -> Result<Option<SemanticTokensResult>> {
1178-
let _p = profile::span("handle_semantic_tokens");
1178+
let _p = profile::span("handle_semantic_tokens_full");
11791179

11801180
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
11811181
let text = snap.analysis.file_text(file_id)?;
@@ -1190,11 +1190,11 @@ pub(crate) fn handle_semantic_tokens(
11901190
Ok(Some(semantic_tokens.into()))
11911191
}
11921192

1193-
pub(crate) fn handle_semantic_tokens_edits(
1193+
pub(crate) fn handle_semantic_tokens_full_delta(
11941194
snap: GlobalStateSnapshot,
1195-
params: SemanticTokensEditsParams,
1196-
) -> Result<Option<SemanticTokensEditResult>> {
1197-
let _p = profile::span("handle_semantic_tokens_edits");
1195+
params: SemanticTokensDeltaParams,
1196+
) -> Result<Option<SemanticTokensFullDeltaResult>> {
1197+
let _p = profile::span("handle_semantic_tokens_full_delta");
11981198

11991199
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
12001200
let text = snap.analysis.file_text(file_id)?;
@@ -1209,9 +1209,9 @@ pub(crate) fn handle_semantic_tokens_edits(
12091209

12101210
if let Some(prev_id) = &cached_tokens.result_id {
12111211
if *prev_id == params.previous_result_id {
1212-
let edits = to_proto::semantic_token_edits(&cached_tokens, &semantic_tokens);
1212+
let delta = to_proto::semantic_token_delta(&cached_tokens, &semantic_tokens);
12131213
*cached_tokens = semantic_tokens;
1214-
return Ok(Some(edits.into()));
1214+
return Ok(Some(delta.into()));
12151215
}
12161216
}
12171217

crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,11 @@ impl GlobalState {
407407
.on::<lsp_types::request::CallHierarchyOutgoingCalls>(
408408
handlers::handle_call_hierarchy_outgoing,
409409
)?
410-
.on::<lsp_types::request::SemanticTokensRequest>(handlers::handle_semantic_tokens)?
411-
.on::<lsp_types::request::SemanticTokensEditsRequest>(
412-
handlers::handle_semantic_tokens_edits,
410+
.on::<lsp_types::request::SemanticTokensFullRequest>(
411+
handlers::handle_semantic_tokens_full,
412+
)?
413+
.on::<lsp_types::request::SemanticTokensFullDeltaRequest>(
414+
handlers::handle_semantic_tokens_full_delta,
413415
)?
414416
.on::<lsp_types::request::SemanticTokensRangeRequest>(
415417
handlers::handle_semantic_tokens_range,

crates/rust-analyzer/src/semantic_tokens.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ macro_rules! define_semantic_token_types {
2424
SemanticTokenType::CLASS,
2525
SemanticTokenType::INTERFACE,
2626
SemanticTokenType::ENUM,
27+
SemanticTokenType::ENUM_MEMBER,
2728
SemanticTokenType::TYPE_PARAMETER,
2829
SemanticTokenType::FUNCTION,
2930
SemanticTokenType::MEMBER,
3031
SemanticTokenType::PROPERTY,
3132
SemanticTokenType::MACRO,
3233
SemanticTokenType::VARIABLE,
3334
SemanticTokenType::PARAMETER,
34-
SemanticTokenType::LABEL,
3535
$($ident),*
3636
];
3737
};
@@ -41,7 +41,6 @@ define_semantic_token_types![
4141
(ATTRIBUTE, "attribute"),
4242
(BOOLEAN, "boolean"),
4343
(BUILTIN_TYPE, "builtinType"),
44-
(ENUM_MEMBER, "enumMember"),
4544
(ESCAPE_SEQUENCE, "escapeSequence"),
4645
(FORMAT_SPECIFIER, "formatSpecifier"),
4746
(GENERIC, "generic"),

crates/rust-analyzer/src/to_proto.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ pub(crate) fn semantic_tokens(
334334
builder.build()
335335
}
336336

337-
pub(crate) fn semantic_token_edits(
337+
pub(crate) fn semantic_token_delta(
338338
previous: &lsp_types::SemanticTokens,
339339
current: &lsp_types::SemanticTokens,
340-
) -> lsp_types::SemanticTokensEdits {
340+
) -> lsp_types::SemanticTokensDelta {
341341
let result_id = current.result_id.clone();
342342
let edits = semantic_tokens::diff_tokens(&previous.data, &current.data);
343-
lsp_types::SemanticTokensEdits { result_id, edits }
343+
lsp_types::SemanticTokensDelta { result_id, edits }
344344
}
345345

346346
fn semantic_token_type_and_modifiers(
@@ -369,7 +369,7 @@ fn semantic_token_type_and_modifiers(
369369
mods |= lsp_types::SemanticTokenModifier::STATIC;
370370
lsp_types::SemanticTokenType::VARIABLE
371371
}
372-
HighlightTag::EnumVariant => semantic_tokens::ENUM_MEMBER,
372+
HighlightTag::EnumVariant => lsp_types::SemanticTokenType::ENUM_MEMBER,
373373
HighlightTag::Macro => lsp_types::SemanticTokenType::MACRO,
374374
HighlightTag::ValueParam => lsp_types::SemanticTokenType::PARAMETER,
375375
HighlightTag::Local => lsp_types::SemanticTokenType::VARIABLE,

editors/code/package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editors/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"dependencies": {
3838
"node-fetch": "^2.6.0",
39-
"vscode-languageclient": "7.0.0-next.1"
39+
"vscode-languageclient": "7.0.0-next.9"
4040
},
4141
"devDependencies": {
4242
"@rollup/plugin-commonjs": "^13.0.2",

editors/code/src/client.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import * as lc from 'vscode-languageclient';
1+
import * as lc from 'vscode-languageclient/node';
22
import * as vscode from 'vscode';
33
import * as ra from '../src/lsp_ext';
4-
import * as Is from 'vscode-languageclient/lib/utils/is';
5-
6-
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
7-
import { SemanticTokensFeature } from 'vscode-languageclient/lib/semanticTokens.proposed';
4+
import * as Is from 'vscode-languageclient/lib/common/utils/is';
85
import { assert } from './util';
96

107
function renderCommand(cmd: ra.CommandLink) {
@@ -57,7 +54,7 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
5754
return hover;
5855
},
5956
(error) => {
60-
client.logFailedRequest(lc.HoverRequest.type, error);
57+
client.handleFailedRequest(lc.HoverRequest.type, error, null);
6158
return Promise.resolve(null);
6259
});
6360
},
@@ -140,12 +137,6 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
140137
);
141138

142139
// To turn on all proposed features use: client.registerProposedFeatures();
143-
// Here we want to enable CallHierarchyFeature and SemanticTokensFeature
144-
// since they are available on stable.
145-
// Note that while these features are stable in vscode their LSP protocol
146-
// implementations are still in the "proposed" category for 3.16.
147-
client.registerFeature(new CallHierarchyFeature(client));
148-
client.registerFeature(new SemanticTokensFeature(client));
149140
client.registerFeature(new ExperimentalFeatures());
150141

151142
return client;

editors/code/src/commands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function memoryUsage(ctx: Ctx): Cmd {
6363
provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> {
6464
if (!vscode.window.activeTextEditor) return '';
6565

66-
return ctx.client.sendRequest(ra.memoryUsage, null).then((mem) => {
66+
return ctx.client.sendRequest(ra.memoryUsage, null).then((mem: any) => {
6767
return 'Per-query memory usage:\n' + mem + '\n(note: database has been cleared)';
6868
});
6969
}
@@ -121,7 +121,7 @@ export function joinLines(ctx: Ctx): Cmd {
121121
textDocument: { uri: editor.document.uri.toString() },
122122
});
123123
editor.edit((builder) => {
124-
client.protocol2CodeConverter.asTextEdits(items).forEach((edit) => {
124+
client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => {
125125
builder.replace(edit.range, edit.newText);
126126
});
127127
});
@@ -140,8 +140,8 @@ export function onEnter(ctx: Ctx): Cmd {
140140
position: client.code2ProtocolConverter.asPosition(
141141
editor.selection.active,
142142
),
143-
}).catch(_error => {
144-
// client.logFailedRequest(OnEnterRequest.type, error);
143+
}).catch((_error: any) => {
144+
// client.handleFailedRequest(OnEnterRequest.type, error, null);
145145
return null;
146146
});
147147
if (!lcEdits) return false;

editors/code/src/ctx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import * as lc from 'vscode-languageclient';
2+
import * as lc from 'vscode-languageclient/node';
33
import * as ra from './lsp_ext';
44

55
import { Config } from './config';

editors/code/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as lc from "vscode-languageclient";
1+
import * as lc from "vscode-languageclient/node";
22
import * as vscode from "vscode";
33
import { strict as nativeAssert } from "assert";
44
import { spawnSync } from "child_process";

0 commit comments

Comments
 (0)