summaryrefslogtreecommitdiff
path: root/cli/lsp/language_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r--cli/lsp/language_server.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 64c7adeb6..c4617df9f 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -196,6 +196,13 @@ impl LanguageServer {
}
}
+ pub async fn inlay_hint(
+ &self,
+ params: InlayHintParams,
+ ) -> LspResult<Option<Vec<InlayHint>>> {
+ self.0.lock().await.inlay_hint(params).await
+ }
+
pub async fn virtual_text_document(
&self,
params: Option<Value>,
@@ -2896,6 +2903,50 @@ impl Inner {
)
}
+ async fn inlay_hint(
+ &self,
+ params: InlayHintParams,
+ ) -> LspResult<Option<Vec<InlayHint>>> {
+ let specifier = self.url_map.normalize_url(&params.text_document.uri);
+ let workspace_settings = self.config.get_workspace_settings();
+ if !self.is_diagnosable(&specifier)
+ || !self.config.specifier_enabled(&specifier)
+ || !workspace_settings.enabled_inlay_hints()
+ {
+ return Ok(None);
+ }
+
+ let mark = self.performance.mark("inlay_hint", Some(&params));
+ let asset_or_doc = self.get_asset_or_document(&specifier)?;
+ let line_index = asset_or_doc.line_index();
+ let range = tsc::TextSpan::from_range(&params.range, line_index.clone())
+ .map_err(|err| {
+ error!("Failed to convert range to text_span: {}", err);
+ LspError::internal_error()
+ })?;
+ let req = tsc::RequestMethod::ProvideInlayHints((
+ specifier.clone(),
+ range,
+ (&workspace_settings).into(),
+ ));
+ let maybe_inlay_hints: Option<Vec<tsc::InlayHint>> = self
+ .ts_server
+ .request(self.snapshot(), req)
+ .await
+ .map_err(|err| {
+ error!("Unable to get inlay hints: {}", err);
+ LspError::internal_error()
+ })?;
+ let maybe_inlay_hints = maybe_inlay_hints.map(|hints| {
+ hints
+ .iter()
+ .map(|hint| hint.to_lsp(line_index.clone()))
+ .collect()
+ });
+ self.performance.measure(mark);
+ Ok(maybe_inlay_hints)
+ }
+
async fn reload_import_registries(&mut self) -> LspResult<Option<Value>> {
fs_util::remove_dir_all_if_exists(&self.module_registries_location)
.await