Unnamed repository; edit this file 'description' to name the repository.
Merge #11935
11935: feat: Switch to LSP inlay hints r=lnicola a=lnicola Co-authored-by: LaurenČ›iu Nicola <[email protected]>
bors[bot] 2022-04-11
parent b1c9a6b · parent bfa2a08 · commit 7a564af
-rw-r--r--crates/rust-analyzer/src/caps.rs3
-rw-r--r--crates/rust-analyzer/src/handlers.rs47
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs46
-rw-r--r--crates/rust-analyzer/src/main_loop.rs2
-rw-r--r--crates/rust-analyzer/src/to_proto.rs21
-rw-r--r--docs/dev/lsp-extensions.md32
-rw-r--r--editors/code/package-lock.json78
-rw-r--r--editors/code/package.json6
-rw-r--r--editors/code/src/client.ts6
-rw-r--r--editors/code/src/commands.ts16
-rw-r--r--editors/code/src/inlay_hints.ts55
-rw-r--r--editors/code/src/lsp_ext.ts7
-rw-r--r--editors/code/src/main.ts2
13 files changed, 87 insertions, 234 deletions
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index 8c19f584f0..ca42bf321e 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -112,11 +112,10 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
.into(),
),
moniker_provider: None,
- inlay_hint_provider: None,
+ inlay_hint_provider: Some(OneOf::Left(true)),
experimental: Some(json!({
"externalDocs": true,
"hoverRange": true,
- "inlayHints": true,
"joinLines": true,
"matchingBrace": true,
"moveItem": true,
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 78118764fa..fb64eeea4f 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -19,11 +19,11 @@ use lsp_types::{
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
CodeLens, CompletionItem, Diagnostic, DiagnosticTag, DocumentFormattingParams, FoldingRange,
- FoldingRangeParams, HoverContents, Location, LocationLink, NumberOrString, Position,
- PrepareRenameResponse, Range, RenameParams, SemanticTokensDeltaParams,
- SemanticTokensFullDeltaResult, SemanticTokensParams, SemanticTokensRangeParams,
- SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, SymbolTag,
- TextDocumentIdentifier, Url, WorkspaceEdit,
+ FoldingRangeParams, HoverContents, InlayHint, InlayHintParams, Location, LocationLink,
+ NumberOrString, Position, PrepareRenameResponse, Range, RenameParams,
+ SemanticTokensDeltaParams, SemanticTokensFullDeltaResult, SemanticTokensParams,
+ SemanticTokensRangeParams, SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation,
+ SymbolTag, TextDocumentIdentifier, Url, WorkspaceEdit,
};
use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
use serde_json::json;
@@ -38,10 +38,7 @@ use crate::{
from_proto,
global_state::{GlobalState, GlobalStateSnapshot},
line_index::LineEndings,
- lsp_ext::{
- self, InlayHint, InlayHintsParams, PositionOrRange, ViewCrateGraphParams,
- WorkspaceSymbolParams,
- },
+ lsp_ext::{self, PositionOrRange, ViewCrateGraphParams, WorkspaceSymbolParams},
lsp_utils::{all_edits_are_disjoint, invalid_params_error},
to_proto, LspError, Result,
};
@@ -1322,29 +1319,25 @@ pub(crate) fn publish_diagnostics(
pub(crate) fn handle_inlay_hints(
snap: GlobalStateSnapshot,
- params: InlayHintsParams,
-) -> Result<Vec<InlayHint>> {
+ params: InlayHintParams,
+) -> Result<Option<Vec<InlayHint>>> {
let _p = profile::span("handle_inlay_hints");
let document_uri = &params.text_document.uri;
let file_id = from_proto::file_id(&snap, document_uri)?;
let line_index = snap.file_line_index(file_id)?;
- let range = params
- .range
- .map(|range| {
- from_proto::file_range(
- &snap,
- TextDocumentIdentifier::new(document_uri.to_owned()),
- range,
- )
- })
- .transpose()?;
+ let range = from_proto::file_range(
+ &snap,
+ TextDocumentIdentifier::new(document_uri.to_owned()),
+ params.range,
+ )?;
let inlay_hints_config = snap.config.inlay_hints();
- Ok(snap
- .analysis
- .inlay_hints(&inlay_hints_config, file_id, range)?
- .into_iter()
- .map(|it| to_proto::inlay_hint(inlay_hints_config.render_colons, &line_index, it))
- .collect())
+ Ok(Some(
+ snap.analysis
+ .inlay_hints(&inlay_hints_config, file_id, Some(range))?
+ .into_iter()
+ .map(|it| to_proto::inlay_hint(inlay_hints_config.render_colons, &line_index, it))
+ .collect(),
+ ))
}
pub(crate) fn handle_call_hierarchy_prepare(
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index b638a57111..489a233a0a 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -236,14 +236,6 @@ pub struct TestInfo {
pub runnable: Runnable,
}
-pub enum InlayHints {}
-
-impl Request for InlayHints {
- type Params = InlayHintsParams;
- type Result = Vec<InlayHint>;
- const METHOD: &'static str = "experimental/inlayHints";
-}
-
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct InlayHintsParams {
@@ -251,44 +243,6 @@ pub struct InlayHintsParams {
pub range: Option<lsp_types::Range>,
}
-#[derive(Eq, PartialEq, Debug, Copy, Clone, Serialize, Deserialize)]
-#[serde(transparent)]
-pub struct InlayHintKind(u8);
-
-impl InlayHintKind {
- pub const TYPE: InlayHintKind = InlayHintKind(1);
- pub const PARAMETER: InlayHintKind = InlayHintKind(2);
-}
-
-#[derive(Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct InlayHint {
- pub label: InlayHintLabel,
- pub position: Position,
- pub kind: Option<InlayHintKind>,
- pub tooltip: Option<String>,
- pub padding_left: Option<bool>,
- pub padding_right: Option<bool>,
-}
-
-#[derive(Debug, Deserialize, Serialize)]
-#[serde(untagged)]
-pub enum InlayHintLabel {
- String(String),
- Parts(Vec<InlayHintLabelPart>),
-}
-
-#[derive(Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct InlayHintLabelPart {
- pub value: String,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub tooltip: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub location: Option<lsp_types::LocationLink>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub command: Option<lsp_types::Command>,
-}
pub enum Ssr {}
impl Request for Ssr {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 2d898d76a6..27ec32b1f4 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -597,7 +597,6 @@ impl GlobalState {
.on::<lsp_ext::ParentModule>(handlers::handle_parent_module)
.on::<lsp_ext::Runnables>(handlers::handle_runnables)
.on::<lsp_ext::RelatedTests>(handlers::handle_related_tests)
- .on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)
.on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)
.on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve)
.on::<lsp_ext::HoverRequest>(handlers::handle_hover)
@@ -611,6 +610,7 @@ impl GlobalState {
.on::<lsp_types::request::GotoDeclaration>(handlers::handle_goto_declaration)
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)
+ .on::<lsp_types::request::InlayHintRequest>(handlers::handle_inlay_hints)
.on::<lsp_types::request::Completion>(handlers::handle_completion)
.on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve)
.on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index e52505d8a1..0588f00678 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -418,14 +418,8 @@ pub(crate) fn inlay_hint(
render_colons: bool,
line_index: &LineIndex,
inlay_hint: InlayHint,
-) -> lsp_ext::InlayHint {
- lsp_ext::InlayHint {
- label: lsp_ext::InlayHintLabel::String(match inlay_hint.kind {
- InlayKind::ParameterHint if render_colons => format!("{}:", inlay_hint.label),
- InlayKind::TypeHint if render_colons => format!(": {}", inlay_hint.label),
- InlayKind::ClosureReturnTypeHint => format!(" -> {}", inlay_hint.label),
- _ => inlay_hint.label.to_string(),
- }),
+) -> lsp_types::InlayHint {
+ lsp_types::InlayHint {
position: match inlay_hint.kind {
// before annotated thing
InlayKind::ParameterHint | InlayKind::ImplicitReborrow => {
@@ -438,10 +432,16 @@ pub(crate) fn inlay_hint(
| InlayKind::GenericParamListHint
| InlayKind::LifetimeHint => position(line_index, inlay_hint.range.end()),
},
+ label: lsp_types::InlayHintLabel::String(match inlay_hint.kind {
+ InlayKind::ParameterHint if render_colons => format!("{}:", inlay_hint.label),
+ InlayKind::TypeHint if render_colons => format!(": {}", inlay_hint.label),
+ InlayKind::ClosureReturnTypeHint => format!(" -> {}", inlay_hint.label),
+ _ => inlay_hint.label.to_string(),
+ }),
kind: match inlay_hint.kind {
- InlayKind::ParameterHint => Some(lsp_ext::InlayHintKind::PARAMETER),
+ InlayKind::ParameterHint => Some(lsp_types::InlayHintKind::PARAMETER),
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
- Some(lsp_ext::InlayHintKind::TYPE)
+ Some(lsp_types::InlayHintKind::TYPE)
}
InlayKind::GenericParamListHint
| InlayKind::LifetimeHint
@@ -465,6 +465,7 @@ pub(crate) fn inlay_hint(
InlayKind::GenericParamListHint => false,
InlayKind::ImplicitReborrow => false,
}),
+ text_edits: None,
}
}
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 516d1caccc..46193a6ff3 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,5 +1,5 @@
<!---
-lsp_ext.rs hash: a61de7db4504a4d1
+lsp_ext.rs hash: 326ad62235135223
If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue:
@@ -571,36 +571,6 @@ interface ExpandedMacro {
Expands macro call at a given position.
-## Inlay Hints
-
-**Method:** `experimental/inlayHints`
-
-This request is sent from client to server to render "inlay hints" -- virtual text inserted into editor to show things like inferred types.
-Generally, the client should re-query inlay hints after every modification.
-Until it gets upstreamed, this follows the VS Code API.
-Upstream issues: https://github.com/microsoft/language-server-protocol/issues/956 , https://github.com/rust-analyzer/rust-analyzer/issues/2797
-
-**Request:**
-
-```typescript
-interface InlayHintsParams {
- textDocument: TextDocumentIdentifier,
-}
-```
-
-**Response:** `InlayHint[]`
-
-```typescript
-interface InlayHint {
- position: Position;
- label: string | InlayHintLabelPart[];
- tooltip?: string | MarkdownString | undefined;
- kind?: InlayHintKind;
- paddingLeft?: boolean;
- paddingRight?: boolean;
-}
-```
-
## Hover Actions
**Experimental Client Capability:** `{ "hoverActions": boolean }`
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json
index 61490d0e47..3c7c643798 100644
--- a/editors/code/package-lock.json
+++ b/editors/code/package-lock.json
@@ -11,11 +11,11 @@
"dependencies": {
"d3": "^7.3.0",
"d3-graphviz": "^4.1.0",
- "vscode-languageclient": "8.0.0-next.12"
+ "vscode-languageclient": "8.0.0-next.14"
},
"devDependencies": {
"@types/node": "~14.17.5",
- "@types/vscode": "~1.65.0",
+ "@types/vscode": "~1.66.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@vscode/test-electron": "^2.1.3",
@@ -138,9 +138,9 @@
"dev": true
},
"node_modules/@types/vscode": {
- "version": "1.65.0",
- "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz",
- "integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==",
+ "version": "1.66.0",
+ "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.66.0.tgz",
+ "integrity": "sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==",
"dev": true
},
"node_modules/@typescript-eslint/eslint-plugin": {
@@ -3915,39 +3915,39 @@
}
},
"node_modules/vscode-jsonrpc": {
- "version": "8.0.0-next.6",
- "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz",
- "integrity": "sha512-6Ld3RYjygn5Ih7CkAtcAwiDQC+rakj2O+PnASfNyYv3sLmm44eJpEKzuPUN30Iy2UB09AZg8T6LBKWTJTEJDVw==",
+ "version": "8.0.0-next.7",
+ "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.7.tgz",
+ "integrity": "sha512-JX/F31LEsims0dAlOTKFE4E+AJMiJvdRSRViifFJSqSN7EzeYyWlfuDchF7g91oRNPZOIWfibTkDf3/UMsQGzQ==",
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/vscode-languageclient": {
- "version": "8.0.0-next.12",
- "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.12.tgz",
- "integrity": "sha512-4+kr1BQcoh+sA5/4XJDJXrQXGQ5Yz/x+WpsVGGzK/TOB7RwQ63ooxG6Ej7i/+aOQM4/QdmcYWmipDtG7vqcOiw==",
+ "version": "8.0.0-next.14",
+ "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.14.tgz",
+ "integrity": "sha512-NqjkOuDTMu8uo+PhoMsV72VO9Gd3wBi/ZpOrkRUOrWKQo7yUdiIw183g8wjH8BImgbK9ZP51HM7TI0ZhCnI1Mw==",
"dependencies": {
"minimatch": "^3.0.4",
"semver": "^7.3.5",
- "vscode-languageserver-protocol": "3.17.0-next.14"
+ "vscode-languageserver-protocol": "3.17.0-next.16"
},
"engines": {
- "vscode": "^1.63.0"
+ "vscode": "^1.66.0"
}
},
"node_modules/vscode-languageserver-protocol": {
- "version": "3.17.0-next.14",
- "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.14.tgz",
- "integrity": "sha512-iangobY8dL6sFZkOx4OhRPJM9gN0I1caUsOVR+MnPozsqQUtwMXmbIcfaIf0Akp0pd3KhJDPf/tdwRX68QGeeA==",
+ "version": "3.17.0-next.16",
+ "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.16.tgz",
+ "integrity": "sha512-tx4DnXw9u3N7vw+bx6n2NKp6FoxoNwiP/biH83AS30I2AnTGyLd7afSeH6Oewn2E8jvB7K15bs12sMppkKOVeQ==",
"dependencies": {
- "vscode-jsonrpc": "8.0.0-next.6",
- "vscode-languageserver-types": "3.17.0-next.7"
+ "vscode-jsonrpc": "8.0.0-next.7",
+ "vscode-languageserver-types": "3.17.0-next.9"
}
},
"node_modules/vscode-languageserver-types": {
- "version": "3.17.0-next.7",
- "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.7.tgz",
- "integrity": "sha512-KH4zdG1qBXxoso61ChgpeoZYyHGJo8bV7Jv4I+fwQ1Ryy59JAxoZ9GAbhR5TeeafHctLcg6RFvY3m8Jqfu17cg=="
+ "version": "3.17.0-next.9",
+ "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
+ "integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A=="
},
"node_modules/which": {
"version": "2.0.2",
@@ -4214,9 +4214,9 @@
"dev": true
},
"@types/vscode": {
- "version": "1.65.0",
- "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz",
- "integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==",
+ "version": "1.66.0",
+ "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.66.0.tgz",
+ "integrity": "sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==",
"dev": true
},
"@typescript-eslint/eslint-plugin": {
@@ -6958,33 +6958,33 @@
}
},
"vscode-jsonrpc": {
- "version": "8.0.0-next.6",
- "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz",
- "integrity": "sha512-6Ld3RYjygn5Ih7CkAtcAwiDQC+rakj2O+PnASfNyYv3sLmm44eJpEKzuPUN30Iy2UB09AZg8T6LBKWTJTEJDVw=="
+ "version": "8.0.0-next.7",
+ "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.7.tgz",
+ "integrity": "sha512-JX/F31LEsims0dAlOTKFE4E+AJMiJvdRSRViifFJSqSN7EzeYyWlfuDchF7g91oRNPZOIWfibTkDf3/UMsQGzQ=="
},
"vscode-languageclient": {
- "version": "8.0.0-next.12",
- "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.12.tgz",
- "integrity": "sha512-4+kr1BQcoh+sA5/4XJDJXrQXGQ5Yz/x+WpsVGGzK/TOB7RwQ63ooxG6Ej7i/+aOQM4/QdmcYWmipDtG7vqcOiw==",
+ "version": "8.0.0-next.14",
+ "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.14.tgz",
+ "integrity": "sha512-NqjkOuDTMu8uo+PhoMsV72VO9Gd3wBi/ZpOrkRUOrWKQo7yUdiIw183g8wjH8BImgbK9ZP51HM7TI0ZhCnI1Mw==",
"requires": {
"minimatch": "^3.0.4",
"semver": "^7.3.5",
- "vscode-languageserver-protocol": "3.17.0-next.14"
+ "vscode-languageserver-protocol": "3.17.0-next.16"
}
},
"vscode-languageserver-protocol": {
- "version": "3.17.0-next.14",
- "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.14.tgz",
- "integrity": "sha512-iangobY8dL6sFZkOx4OhRPJM9gN0I1caUsOVR+MnPozsqQUtwMXmbIcfaIf0Akp0pd3KhJDPf/tdwRX68QGeeA==",
+ "version": "3.17.0-next.16",
+ "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.16.tgz",
+ "integrity": "sha512-tx4DnXw9u3N7vw+bx6n2NKp6FoxoNwiP/biH83AS30I2AnTGyLd7afSeH6Oewn2E8jvB7K15bs12sMppkKOVeQ==",
"requires": {
- "vscode-jsonrpc": "8.0.0-next.6",
- "vscode-languageserver-types": "3.17.0-next.7"
+ "vscode-jsonrpc": "8.0.0-next.7",
+ "vscode-languageserver-types": "3.17.0-next.9"
}
},
"vscode-languageserver-types": {
- "version": "3.17.0-next.7",
- "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.7.tgz",
- "integrity": "sha512-KH4zdG1qBXxoso61ChgpeoZYyHGJo8bV7Jv4I+fwQ1Ryy59JAxoZ9GAbhR5TeeafHctLcg6RFvY3m8Jqfu17cg=="
+ "version": "3.17.0-next.9",
+ "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
+ "integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A=="
},
"which": {
"version": "2.0.2",
diff --git a/editors/code/package.json b/editors/code/package.json
index b7bc60a3b8..bbc7feef7e 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -21,7 +21,7 @@
"Programming Languages"
],
"engines": {
- "vscode": "^1.65.0"
+ "vscode": "^1.66.0"
},
"enabledApiProposals": [],
"scripts": {
@@ -36,13 +36,13 @@
"test": "node ./out/tests/runTests.js"
},
"dependencies": {
- "vscode-languageclient": "8.0.0-next.12",
+ "vscode-languageclient": "8.0.0-next.14",
"d3": "^7.3.0",
"d3-graphviz": "^4.1.0"
},
"devDependencies": {
"@types/node": "~14.17.5",
- "@types/vscode": "~1.65.0",
+ "@types/vscode": "~1.66.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@vscode/test-electron": "^2.1.3",
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 26567c6df3..f7520f6c43 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -90,9 +90,9 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
const params: lc.CodeActionParams = {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
range: client.code2ProtocolConverter.asRange(range),
- context: client.code2ProtocolConverter.asCodeActionContext(context)
+ context: await client.code2ProtocolConverter.asCodeActionContext(context, token)
};
- return client.sendRequest(lc.CodeActionRequest.type, params, token).then((values) => {
+ return client.sendRequest(lc.CodeActionRequest.type, params, token).then(async (values) => {
if (values === null) return undefined;
const result: (vscode.CodeAction | vscode.Command)[] = [];
const groups = new Map<string, { index: number; items: vscode.CodeAction[] }>();
@@ -100,7 +100,7 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
// In our case we expect to get code edits only from diagnostics
if (lc.CodeAction.is(item)) {
assert(!item.command, "We don't expect to receive commands in CodeActions");
- const action = client.protocol2CodeConverter.asCodeAction(item);
+ const action = await client.protocol2CodeConverter.asCodeAction(item, token);
result.push(action);
continue;
}
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 5581aac22f..4b2ac44801 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -127,8 +127,8 @@ export function joinLines(ctx: Ctx): Cmd {
ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)),
textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
});
- await editor.edit((builder) => {
- client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => {
+ await editor.edit(async (builder) => {
+ (await client.protocol2CodeConverter.asTextEdits(items)).forEach((edit: any) => {
builder.replace(edit.range, edit.newText);
});
});
@@ -157,7 +157,7 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
if (!lcEdits) return;
- const edits = client.protocol2CodeConverter.asTextEdits(lcEdits);
+ const edits = await client.protocol2CodeConverter.asTextEdits(lcEdits);
await applySnippetTextEdits(editor, edits);
};
}
@@ -180,7 +180,7 @@ export function onEnter(ctx: Ctx): Cmd {
});
if (!lcEdits) return false;
- const edits = client.protocol2CodeConverter.asTextEdits(lcEdits);
+ const edits = await client.protocol2CodeConverter.asTextEdits(lcEdits);
await applySnippetTextEdits(editor, edits);
return true;
}
@@ -277,12 +277,12 @@ export function ssr(ctx: Ctx): Cmd {
location: vscode.ProgressLocation.Notification,
title: "Structured search replace in progress...",
cancellable: false,
- }, async (_progress, _token) => {
+ }, async (_progress, token) => {
const edit = await client.sendRequest(ra.ssr, {
query: request, parseOnly: false, textDocument, position, selections,
});
- await vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edit));
+ await vscode.workspace.applyEdit(await client.protocol2CodeConverter.asWorkspaceEdit(edit, token));
});
};
}
@@ -728,11 +728,11 @@ export function resolveCodeAction(ctx: Ctx): Cmd {
return;
}
const itemEdit = item.edit;
- const edit = client.protocol2CodeConverter.asWorkspaceEdit(itemEdit);
+ const edit = await client.protocol2CodeConverter.asWorkspaceEdit(itemEdit);
// filter out all text edits and recreate the WorkspaceEdit without them so we can apply
// snippet edits on our own
const lcFileSystemEdit = { ...itemEdit, documentChanges: itemEdit.documentChanges?.filter(change => "kind" in change) };
- const fileSystemEdit = client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit);
+ const fileSystemEdit = await client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit);
await vscode.workspace.applyEdit(fileSystemEdit);
await applySnippetWorkspaceEdit(edit);
};
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
deleted file mode 100644
index 3f7ddedddf..0000000000
--- a/editors/code/src/inlay_hints.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import * as vscode from 'vscode';
-import * as ra from './lsp_ext';
-
-import { Ctx, Disposable } from './ctx';
-import { sendRequestWithRetry, isRustDocument } from './util';
-
-export function activateInlayHints(ctx: Ctx) {
- const maybeUpdater = {
- hintsProvider: null as Disposable | null,
- updateHintsEventEmitter: new vscode.EventEmitter<void>(),
-
- async onConfigChange() {
- this.dispose();
-
- const anyEnabled = ctx.config.inlayHints.typeHints
- || ctx.config.inlayHints.parameterHints
- || ctx.config.inlayHints.chainingHints
- || ctx.config.inlayHints.closureReturnTypeHints;
- const enabled = ctx.config.inlayHints.enable && anyEnabled;
- if (!enabled) return;
-
- const event = this.updateHintsEventEmitter.event;
- this.hintsProvider = vscode.languages.registerInlayHintsProvider({ scheme: 'file', language: 'rust' }, new class implements vscode.InlayHintsProvider {
- onDidChangeInlayHints = event;
- async provideInlayHints(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise<vscode.InlayHint[]> {
- const request = { textDocument: { uri: document.uri.toString() }, range: { start: range.start, end: range.end } };
- const hints = await sendRequestWithRetry(ctx.client, ra.inlayHints, request, token).catch(_ => null);
- if (hints == null) {
- return [];
- } else {
- return hints;
- }
- }
- });
- },
-
- onDidChangeTextDocument({ contentChanges, document }: vscode.TextDocumentChangeEvent) {
- if (contentChanges.length === 0 || !isRustDocument(document)) return;
- this.updateHintsEventEmitter.fire();
- },
-
- dispose() {
- this.hintsProvider?.dispose();
- this.hintsProvider = null;
- this.updateHintsEventEmitter.dispose();
- },
- };
-
- ctx.pushCleanup(maybeUpdater);
-
- vscode.workspace.onDidChangeConfiguration(maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions);
- vscode.workspace.onDidChangeTextDocument(maybeUpdater.onDidChangeTextDocument, maybeUpdater, ctx.subscriptions);
-
- maybeUpdater.onConfigChange().catch(console.error);
-}
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index 0ae5e93a73..61078b58c7 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -2,7 +2,6 @@
* This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
*/
-import { InlayHint } from "vscode";
import * as lc from "vscode-languageclient";
export interface AnalyzerStatusParams {
@@ -102,12 +101,6 @@ export interface TestInfo {
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>("rust-analyzer/relatedTests");
-export interface InlayHintsParams {
- textDocument: lc.TextDocumentIdentifier;
- range: lc.Range;
-}
-export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("experimental/inlayHints");
-
export interface SsrParams {
query: string;
parseOnly: boolean;
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 36a095bdd3..0451e4c3d6 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -2,7 +2,6 @@ import * as vscode from 'vscode';
import * as os from "os";
import * as commands from './commands';
-import { activateInlayHints } from './inlay_hints';
import { Ctx } from './ctx';
import { Config } from './config';
import { log, isValidExecutable, isRustDocument } from './util';
@@ -54,7 +53,6 @@ async function tryActivate(context: vscode.ExtensionContext) {
}
await initCommonContext(context, ctx);
- activateInlayHints(ctx);
warnAboutExtensionConflicts();
ctx.pushCleanup(configureLanguage());