.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,
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;
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,
};
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 = ¶ms.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(
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 {
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 {
.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)
.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)
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 => {
| 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
InlayKind::GenericParamListHint => false,
InlayKind::ImplicitReborrow => false,
}),
+ text_edits: None,
}
}
<!---
-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:
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 }`
"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",
"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": {
}
},
"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",
"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": {
}
},
"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",
"Programming Languages"
],
"engines": {
- "vscode": "^1.65.0"
+ "vscode": "^1.66.0"
},
"enabledApiProposals": [],
"scripts": {
"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",
+++ /dev/null
-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);
-}
* This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
*/
-import { InlayHint } from "vscode";
import * as lc from "vscode-languageclient";
export interface AnalyzerStatusParams {
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;
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';
}
await initCommonContext(context, ctx);
- activateInlayHints(ctx);
warnAboutExtensionConflicts();
ctx.pushCleanup(configureLanguage());