Version the inlay hint resolve data

This commit is contained in:
Jonas Schievink 2022-11-29 19:20:32 +01:00
parent e69fb5e9ef
commit 335cb26050
4 changed files with 39 additions and 7 deletions

View File

@ -67,7 +67,15 @@ pub(crate) fn file_range(
text_document_identifier: lsp_types::TextDocumentIdentifier, text_document_identifier: lsp_types::TextDocumentIdentifier,
range: lsp_types::Range, range: lsp_types::Range,
) -> Result<FileRange> { ) -> Result<FileRange> {
let file_id = file_id(snap, &text_document_identifier.uri)?; file_range_uri(snap, &text_document_identifier.uri, range)
}
pub(crate) fn file_range_uri(
snap: &GlobalStateSnapshot,
document: &lsp_types::Url,
range: lsp_types::Range,
) -> Result<FileRange> {
let file_id = file_id(snap, document)?;
let line_index = snap.file_line_index(file_id)?; let line_index = snap.file_line_index(file_id)?;
let range = text_range(&line_index, range)?; let range = text_range(&line_index, range)?;
Ok(FileRange { file_id, range }) Ok(FileRange { file_id, range })

View File

@ -29,6 +29,7 @@ use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
use serde_json::json; use serde_json::json;
use stdx::{format_to, never}; use stdx::{format_to, never};
use syntax::{algo, ast, AstNode, TextRange, TextSize}; use syntax::{algo, ast, AstNode, TextRange, TextSize};
use tracing::error;
use vfs::AbsPathBuf; use vfs::AbsPathBuf;
use crate::{ use crate::{
@ -1372,9 +1373,26 @@ pub(crate) fn handle_inlay_hints_resolve(
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?; let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
let file_range = from_proto::file_range( match snap.url_file_version(&resolve_data.text_document.uri) {
Some(version) if version == resolve_data.text_document.version => {}
Some(version) => {
error!(
"attempted inlayHints/resolve of '{}' at version {} while server version is {}",
resolve_data.text_document.uri, resolve_data.text_document.version, version,
);
return Ok(hint);
}
None => {
error!(
"attempted inlayHints/resolve of unknown file '{}' at version {}",
resolve_data.text_document.uri, resolve_data.text_document.version,
);
return Ok(hint);
}
}
let file_range = from_proto::file_range_uri(
&snap, &snap,
resolve_data.text_document, &resolve_data.text_document.uri,
match resolve_data.position { match resolve_data.position {
PositionOrRange::Position(pos) => Range::new(pos, pos), PositionOrRange::Position(pos) => Range::new(pos, pos),
PositionOrRange::Range(range) => range, PositionOrRange::Range(range) => range,

View File

@ -3,11 +3,11 @@
use std::{collections::HashMap, path::PathBuf}; use std::{collections::HashMap, path::PathBuf};
use lsp_types::request::Request; use lsp_types::request::Request;
use lsp_types::PositionEncodingKind;
use lsp_types::{ use lsp_types::{
notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams, notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams,
PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams, PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams,
}; };
use lsp_types::{PositionEncodingKind, VersionedTextDocumentIdentifier};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub enum AnalyzerStatus {} pub enum AnalyzerStatus {}
@ -550,7 +550,7 @@ pub struct CompletionResolveData {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct InlayHintResolveData { pub struct InlayHintResolveData {
pub text_document: TextDocumentIdentifier, pub text_document: VersionedTextDocumentIdentifier,
pub position: PositionOrRange, pub position: PositionOrRange,
} }

View File

@ -492,7 +492,10 @@ pub(crate) fn inlay_hint(
let uri = url(snap, file_id); let uri = url(snap, file_id);
let line_index = snap.file_line_index(file_id).ok()?; let line_index = snap.file_line_index(file_id).ok()?;
let text_document = lsp_types::TextDocumentIdentifier { uri }; let text_document = lsp_types::VersionedTextDocumentIdentifier {
version: snap.url_file_version(&uri)?,
uri,
};
to_value(lsp_ext::InlayHintResolveData { to_value(lsp_ext::InlayHintResolveData {
text_document, text_document,
position: lsp_ext::PositionOrRange::Position(position(&line_index, offset)), position: lsp_ext::PositionOrRange::Position(position(&line_index, offset)),
@ -501,7 +504,10 @@ pub(crate) fn inlay_hint(
} }
Some(ide::InlayTooltip::HoverRanged(file_id, text_range)) => { Some(ide::InlayTooltip::HoverRanged(file_id, text_range)) => {
let uri = url(snap, file_id); let uri = url(snap, file_id);
let text_document = lsp_types::TextDocumentIdentifier { uri }; let text_document = lsp_types::VersionedTextDocumentIdentifier {
version: snap.url_file_version(&uri)?,
uri,
};
let line_index = snap.file_line_index(file_id).ok()?; let line_index = snap.file_line_index(file_id).ok()?;
to_value(lsp_ext::InlayHintResolveData { to_value(lsp_ext::InlayHintResolveData {
text_document, text_document,