]> git.lizzy.rs Git - rust.git/commitdiff
Request a refresh of semantic tokens if things are loaded up
authorkjeremy <kjeremy@gmail.com>
Fri, 23 Oct 2020 21:36:22 +0000 (17:36 -0400)
committerkjeremy <kjeremy@gmail.com>
Mon, 26 Oct 2020 13:23:34 +0000 (09:23 -0400)
crates/rust-analyzer/src/config.rs
crates/rust-analyzer/src/main_loop.rs

index 1b9b24698a96057d153e71efe36399bf63cd859c..2ed6a0d82e2127b4f6b9f60ba1c2487061013624 100644 (file)
@@ -47,6 +47,7 @@ pub struct Config {
     pub call_info_full: bool,
     pub lens: LensConfig,
     pub hover: HoverConfig,
+    pub semantic_tokens_refresh: bool,
 
     pub with_sysroot: bool,
     pub linked_projects: Vec<LinkedProject>,
@@ -193,6 +194,7 @@ pub fn new(root_path: AbsPathBuf) -> Self {
             call_info_full: true,
             lens: LensConfig::default(),
             hover: HoverConfig::default(),
+            semantic_tokens_refresh: false,
             linked_projects: Vec::new(),
             root_path,
         }
@@ -402,6 +404,14 @@ pub fn update_caps(&mut self, caps: &ClientCapabilities) {
             self.client_caps.hover_actions = get_bool("hoverActions");
             self.client_caps.status_notification = get_bool("statusNotification");
         }
+
+        if let Some(workspace_caps) = caps.workspace.as_ref() {
+            if let Some(refresh_support) =
+                workspace_caps.semantic_tokens.as_ref().and_then(|it| it.refresh_support)
+            {
+                self.semantic_tokens_refresh = refresh_support;
+            }
+        }
     }
 }
 
index ed52927330439d5133d6168ad42464737b932dd0..ff855fe1a6425ba0941feb6b5b55c2de83d9fe6a 100644 (file)
@@ -330,6 +330,12 @@ fn handle_event(&mut self, event: Event) -> Result<()> {
                 .collect::<Vec<_>>();
 
             self.update_file_notifications_on_threadpool(subscriptions);
+
+            // Refresh semantic tokens if the client supports it.
+            if self.config.semantic_tokens_refresh {
+                self.semantic_tokens_cache.lock().clear();
+                self.send_request::<lsp_types::request::SemanticTokensRefesh>((), |_, _| ());
+            }
         }
 
         if let Some(diagnostic_changes) = self.diagnostics.take_changes() {