Switch to LSP inlay hints

This commit is contained in:
Laurențiu Nicola 2022-04-08 13:20:21 +03:00
parent bc56920757
commit d3d6267112
11 changed files with 76 additions and 223 deletions

View File

@ -112,11 +112,10 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
.into(), .into(),
), ),
moniker_provider: None, moniker_provider: None,
inlay_hint_provider: None, inlay_hint_provider: Some(OneOf::Left(true)),
experimental: Some(json!({ experimental: Some(json!({
"externalDocs": true, "externalDocs": true,
"hoverRange": true, "hoverRange": true,
"inlayHints": true,
"joinLines": true, "joinLines": true,
"matchingBrace": true, "matchingBrace": true,
"moveItem": true, "moveItem": true,

View File

@ -19,11 +19,11 @@ use lsp_types::{
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams, CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
CodeLens, CompletionItem, Diagnostic, DiagnosticTag, DocumentFormattingParams, FoldingRange, CodeLens, CompletionItem, Diagnostic, DiagnosticTag, DocumentFormattingParams, FoldingRange,
FoldingRangeParams, HoverContents, Location, LocationLink, NumberOrString, Position, FoldingRangeParams, HoverContents, InlayHint, InlayHintParams, Location, LocationLink,
PrepareRenameResponse, Range, RenameParams, SemanticTokensDeltaParams, NumberOrString, Position, PrepareRenameResponse, Range, RenameParams,
SemanticTokensFullDeltaResult, SemanticTokensParams, SemanticTokensRangeParams, SemanticTokensDeltaParams, SemanticTokensFullDeltaResult, SemanticTokensParams,
SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, SymbolTag, SemanticTokensRangeParams, SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation,
TextDocumentIdentifier, Url, WorkspaceEdit, SymbolTag, TextDocumentIdentifier, Url, WorkspaceEdit,
}; };
use project_model::{ManifestPath, ProjectWorkspace, TargetKind}; use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
use serde_json::json; use serde_json::json;
@ -38,10 +38,7 @@ use crate::{
from_proto, from_proto,
global_state::{GlobalState, GlobalStateSnapshot}, global_state::{GlobalState, GlobalStateSnapshot},
line_index::LineEndings, line_index::LineEndings,
lsp_ext::{ lsp_ext::{self, PositionOrRange, ViewCrateGraphParams, WorkspaceSymbolParams},
self, InlayHint, InlayHintsParams, PositionOrRange, ViewCrateGraphParams,
WorkspaceSymbolParams,
},
lsp_utils::{all_edits_are_disjoint, invalid_params_error}, lsp_utils::{all_edits_are_disjoint, invalid_params_error},
to_proto, LspError, Result, to_proto, LspError, Result,
}; };
@ -1322,29 +1319,25 @@ pub(crate) fn publish_diagnostics(
pub(crate) fn handle_inlay_hints( pub(crate) fn handle_inlay_hints(
snap: GlobalStateSnapshot, snap: GlobalStateSnapshot,
params: InlayHintsParams, params: InlayHintParams,
) -> Result<Vec<InlayHint>> { ) -> Result<Option<Vec<InlayHint>>> {
let _p = profile::span("handle_inlay_hints"); let _p = profile::span("handle_inlay_hints");
let document_uri = &params.text_document.uri; let document_uri = &params.text_document.uri;
let file_id = from_proto::file_id(&snap, document_uri)?; let file_id = from_proto::file_id(&snap, document_uri)?;
let line_index = snap.file_line_index(file_id)?; let line_index = snap.file_line_index(file_id)?;
let range = params let range = from_proto::file_range(
.range &snap,
.map(|range| { TextDocumentIdentifier::new(document_uri.to_owned()),
from_proto::file_range( params.range,
&snap, )?;
TextDocumentIdentifier::new(document_uri.to_owned()),
range,
)
})
.transpose()?;
let inlay_hints_config = snap.config.inlay_hints(); let inlay_hints_config = snap.config.inlay_hints();
Ok(snap Ok(Some(
.analysis snap.analysis
.inlay_hints(&inlay_hints_config, file_id, range)? .inlay_hints(&inlay_hints_config, file_id, Some(range))?
.into_iter() .into_iter()
.map(|it| to_proto::inlay_hint(inlay_hints_config.render_colons, &line_index, it)) .map(|it| to_proto::inlay_hint(inlay_hints_config.render_colons, &line_index, it))
.collect()) .collect(),
))
} }
pub(crate) fn handle_call_hierarchy_prepare( pub(crate) fn handle_call_hierarchy_prepare(

View File

@ -236,14 +236,6 @@ pub struct TestInfo {
pub runnable: Runnable, 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)] #[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct InlayHintsParams { pub struct InlayHintsParams {
@ -251,44 +243,6 @@ pub struct InlayHintsParams {
pub range: Option<lsp_types::Range>, 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 {} pub enum Ssr {}
impl Request for Ssr { impl Request for Ssr {

View File

@ -597,7 +597,6 @@ impl GlobalState {
.on::<lsp_ext::ParentModule>(handlers::handle_parent_module) .on::<lsp_ext::ParentModule>(handlers::handle_parent_module)
.on::<lsp_ext::Runnables>(handlers::handle_runnables) .on::<lsp_ext::Runnables>(handlers::handle_runnables)
.on::<lsp_ext::RelatedTests>(handlers::handle_related_tests) .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::CodeActionRequest>(handlers::handle_code_action)
.on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve) .on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve)
.on::<lsp_ext::HoverRequest>(handlers::handle_hover) .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::GotoDeclaration>(handlers::handle_goto_declaration)
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation) .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition) .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::Completion>(handlers::handle_completion)
.on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve) .on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve)
.on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens) .on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)

View File

@ -418,14 +418,8 @@ pub(crate) fn inlay_hint(
render_colons: bool, render_colons: bool,
line_index: &LineIndex, line_index: &LineIndex,
inlay_hint: InlayHint, inlay_hint: InlayHint,
) -> lsp_ext::InlayHint { ) -> lsp_types::InlayHint {
lsp_ext::InlayHint { lsp_types::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(),
}),
position: match inlay_hint.kind { position: match inlay_hint.kind {
// before annotated thing // before annotated thing
InlayKind::ParameterHint | InlayKind::ImplicitReborrow => { InlayKind::ParameterHint | InlayKind::ImplicitReborrow => {
@ -438,10 +432,16 @@ pub(crate) fn inlay_hint(
| InlayKind::GenericParamListHint | InlayKind::GenericParamListHint
| InlayKind::LifetimeHint => position(line_index, inlay_hint.range.end()), | 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 { 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 => { InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
Some(lsp_ext::InlayHintKind::TYPE) Some(lsp_types::InlayHintKind::TYPE)
} }
InlayKind::GenericParamListHint InlayKind::GenericParamListHint
| InlayKind::LifetimeHint | InlayKind::LifetimeHint
@ -465,6 +465,7 @@ pub(crate) fn inlay_hint(
InlayKind::GenericParamListHint => false, InlayKind::GenericParamListHint => false,
InlayKind::ImplicitReborrow => false, InlayKind::ImplicitReborrow => false,
}), }),
text_edits: None,
} }
} }

View File

@ -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 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: need to adjust this doc as well and ping this issue:
@ -571,36 +571,6 @@ interface ExpandedMacro {
Expands macro call at a given position. 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 ## Hover Actions
**Experimental Client Capability:** `{ "hoverActions": boolean }` **Experimental Client Capability:** `{ "hoverActions": boolean }`

View File

@ -11,11 +11,11 @@
"dependencies": { "dependencies": {
"d3": "^7.3.0", "d3": "^7.3.0",
"d3-graphviz": "^4.1.0", "d3-graphviz": "^4.1.0",
"vscode-languageclient": "8.0.0-next.12" "vscode-languageclient": "8.0.0-next.14"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "~14.17.5", "@types/node": "~14.17.5",
"@types/vscode": "~1.65.0", "@types/vscode": "~1.66.0",
"@typescript-eslint/eslint-plugin": "^5.16.0", "@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0", "@typescript-eslint/parser": "^5.16.0",
"@vscode/test-electron": "^2.1.3", "@vscode/test-electron": "^2.1.3",
@ -138,9 +138,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/vscode": { "node_modules/@types/vscode": {
"version": "1.65.0", "version": "1.66.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.66.0.tgz",
"integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==", "integrity": "sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==",
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
@ -3915,39 +3915,39 @@
} }
}, },
"node_modules/vscode-jsonrpc": { "node_modules/vscode-jsonrpc": {
"version": "8.0.0-next.6", "version": "8.0.0-next.7",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.7.tgz",
"integrity": "sha512-6Ld3RYjygn5Ih7CkAtcAwiDQC+rakj2O+PnASfNyYv3sLmm44eJpEKzuPUN30Iy2UB09AZg8T6LBKWTJTEJDVw==", "integrity": "sha512-JX/F31LEsims0dAlOTKFE4E+AJMiJvdRSRViifFJSqSN7EzeYyWlfuDchF7g91oRNPZOIWfibTkDf3/UMsQGzQ==",
"engines": { "engines": {
"node": ">=14.0.0" "node": ">=14.0.0"
} }
}, },
"node_modules/vscode-languageclient": { "node_modules/vscode-languageclient": {
"version": "8.0.0-next.12", "version": "8.0.0-next.14",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.12.tgz", "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.14.tgz",
"integrity": "sha512-4+kr1BQcoh+sA5/4XJDJXrQXGQ5Yz/x+WpsVGGzK/TOB7RwQ63ooxG6Ej7i/+aOQM4/QdmcYWmipDtG7vqcOiw==", "integrity": "sha512-NqjkOuDTMu8uo+PhoMsV72VO9Gd3wBi/ZpOrkRUOrWKQo7yUdiIw183g8wjH8BImgbK9ZP51HM7TI0ZhCnI1Mw==",
"dependencies": { "dependencies": {
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"semver": "^7.3.5", "semver": "^7.3.5",
"vscode-languageserver-protocol": "3.17.0-next.14" "vscode-languageserver-protocol": "3.17.0-next.16"
}, },
"engines": { "engines": {
"vscode": "^1.63.0" "vscode": "^1.66.0"
} }
}, },
"node_modules/vscode-languageserver-protocol": { "node_modules/vscode-languageserver-protocol": {
"version": "3.17.0-next.14", "version": "3.17.0-next.16",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.14.tgz", "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.16.tgz",
"integrity": "sha512-iangobY8dL6sFZkOx4OhRPJM9gN0I1caUsOVR+MnPozsqQUtwMXmbIcfaIf0Akp0pd3KhJDPf/tdwRX68QGeeA==", "integrity": "sha512-tx4DnXw9u3N7vw+bx6n2NKp6FoxoNwiP/biH83AS30I2AnTGyLd7afSeH6Oewn2E8jvB7K15bs12sMppkKOVeQ==",
"dependencies": { "dependencies": {
"vscode-jsonrpc": "8.0.0-next.6", "vscode-jsonrpc": "8.0.0-next.7",
"vscode-languageserver-types": "3.17.0-next.7" "vscode-languageserver-types": "3.17.0-next.9"
} }
}, },
"node_modules/vscode-languageserver-types": { "node_modules/vscode-languageserver-types": {
"version": "3.17.0-next.7", "version": "3.17.0-next.9",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.7.tgz", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
"integrity": "sha512-KH4zdG1qBXxoso61ChgpeoZYyHGJo8bV7Jv4I+fwQ1Ryy59JAxoZ9GAbhR5TeeafHctLcg6RFvY3m8Jqfu17cg==" "integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A=="
}, },
"node_modules/which": { "node_modules/which": {
"version": "2.0.2", "version": "2.0.2",
@ -4214,9 +4214,9 @@
"dev": true "dev": true
}, },
"@types/vscode": { "@types/vscode": {
"version": "1.65.0", "version": "1.66.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.66.0.tgz",
"integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==", "integrity": "sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==",
"dev": true "dev": true
}, },
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
@ -6958,33 +6958,33 @@
} }
}, },
"vscode-jsonrpc": { "vscode-jsonrpc": {
"version": "8.0.0-next.6", "version": "8.0.0-next.7",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.6.tgz", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.7.tgz",
"integrity": "sha512-6Ld3RYjygn5Ih7CkAtcAwiDQC+rakj2O+PnASfNyYv3sLmm44eJpEKzuPUN30Iy2UB09AZg8T6LBKWTJTEJDVw==" "integrity": "sha512-JX/F31LEsims0dAlOTKFE4E+AJMiJvdRSRViifFJSqSN7EzeYyWlfuDchF7g91oRNPZOIWfibTkDf3/UMsQGzQ=="
}, },
"vscode-languageclient": { "vscode-languageclient": {
"version": "8.0.0-next.12", "version": "8.0.0-next.14",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.12.tgz", "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.0-next.14.tgz",
"integrity": "sha512-4+kr1BQcoh+sA5/4XJDJXrQXGQ5Yz/x+WpsVGGzK/TOB7RwQ63ooxG6Ej7i/+aOQM4/QdmcYWmipDtG7vqcOiw==", "integrity": "sha512-NqjkOuDTMu8uo+PhoMsV72VO9Gd3wBi/ZpOrkRUOrWKQo7yUdiIw183g8wjH8BImgbK9ZP51HM7TI0ZhCnI1Mw==",
"requires": { "requires": {
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"semver": "^7.3.5", "semver": "^7.3.5",
"vscode-languageserver-protocol": "3.17.0-next.14" "vscode-languageserver-protocol": "3.17.0-next.16"
} }
}, },
"vscode-languageserver-protocol": { "vscode-languageserver-protocol": {
"version": "3.17.0-next.14", "version": "3.17.0-next.16",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.14.tgz", "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.16.tgz",
"integrity": "sha512-iangobY8dL6sFZkOx4OhRPJM9gN0I1caUsOVR+MnPozsqQUtwMXmbIcfaIf0Akp0pd3KhJDPf/tdwRX68QGeeA==", "integrity": "sha512-tx4DnXw9u3N7vw+bx6n2NKp6FoxoNwiP/biH83AS30I2AnTGyLd7afSeH6Oewn2E8jvB7K15bs12sMppkKOVeQ==",
"requires": { "requires": {
"vscode-jsonrpc": "8.0.0-next.6", "vscode-jsonrpc": "8.0.0-next.7",
"vscode-languageserver-types": "3.17.0-next.7" "vscode-languageserver-types": "3.17.0-next.9"
} }
}, },
"vscode-languageserver-types": { "vscode-languageserver-types": {
"version": "3.17.0-next.7", "version": "3.17.0-next.9",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.7.tgz", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
"integrity": "sha512-KH4zdG1qBXxoso61ChgpeoZYyHGJo8bV7Jv4I+fwQ1Ryy59JAxoZ9GAbhR5TeeafHctLcg6RFvY3m8Jqfu17cg==" "integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A=="
}, },
"which": { "which": {
"version": "2.0.2", "version": "2.0.2",

View File

@ -21,7 +21,7 @@
"Programming Languages" "Programming Languages"
], ],
"engines": { "engines": {
"vscode": "^1.65.0" "vscode": "^1.66.0"
}, },
"enabledApiProposals": [], "enabledApiProposals": [],
"scripts": { "scripts": {
@ -36,13 +36,13 @@
"test": "node ./out/tests/runTests.js" "test": "node ./out/tests/runTests.js"
}, },
"dependencies": { "dependencies": {
"vscode-languageclient": "8.0.0-next.12", "vscode-languageclient": "8.0.0-next.14",
"d3": "^7.3.0", "d3": "^7.3.0",
"d3-graphviz": "^4.1.0" "d3-graphviz": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "~14.17.5", "@types/node": "~14.17.5",
"@types/vscode": "~1.65.0", "@types/vscode": "~1.66.0",
"@typescript-eslint/eslint-plugin": "^5.16.0", "@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0", "@typescript-eslint/parser": "^5.16.0",
"@vscode/test-electron": "^2.1.3", "@vscode/test-electron": "^2.1.3",

View File

@ -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);
}

View File

@ -2,7 +2,6 @@
* This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations. * This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
*/ */
import { InlayHint } from "vscode";
import * as lc from "vscode-languageclient"; import * as lc from "vscode-languageclient";
export interface AnalyzerStatusParams { export interface AnalyzerStatusParams {
@ -102,12 +101,6 @@ export interface TestInfo {
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>("rust-analyzer/relatedTests"); 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 { export interface SsrParams {
query: string; query: string;
parseOnly: boolean; parseOnly: boolean;

View File

@ -2,7 +2,6 @@ import * as vscode from 'vscode';
import * as os from "os"; import * as os from "os";
import * as commands from './commands'; import * as commands from './commands';
import { activateInlayHints } from './inlay_hints';
import { Ctx } from './ctx'; import { Ctx } from './ctx';
import { Config } from './config'; import { Config } from './config';
import { log, isValidExecutable, isRustDocument } from './util'; import { log, isValidExecutable, isRustDocument } from './util';
@ -54,7 +53,6 @@ async function tryActivate(context: vscode.ExtensionContext) {
} }
await initCommonContext(context, ctx); await initCommonContext(context, ctx);
activateInlayHints(ctx);
warnAboutExtensionConflicts(); warnAboutExtensionConflicts();
ctx.pushCleanup(configureLanguage()); ctx.pushCleanup(configureLanguage());