]> git.lizzy.rs Git - rust.git/commitdiff
Latest LSP 3.16 protocol
authorkjeremy <kjeremy@gmail.com>
Mon, 16 Nov 2020 20:10:13 +0000 (15:10 -0500)
committerkjeremy <kjeremy@gmail.com>
Mon, 16 Nov 2020 20:10:13 +0000 (15:10 -0500)
Pulls in https://github.com/gluon-lang/lsp-types/pull/186

12 files changed:
Cargo.lock
crates/rust-analyzer/Cargo.toml
crates/rust-analyzer/src/caps.rs
crates/rust-analyzer/src/diagnostics/to_proto.rs
crates/rust-analyzer/src/document.rs
crates/rust-analyzer/src/global_state.rs
crates/rust-analyzer/src/lsp_ext.rs
crates/rust-analyzer/src/lsp_utils.rs
crates/rust-analyzer/src/main_loop.rs
crates/rust-analyzer/src/to_proto.rs
crates/rust-analyzer/tests/rust-analyzer/support.rs
docs/dev/lsp-extensions.md

index 715a809789c70f527213d227d0cc5117572ede52..09215a37a2be110cfc2cb0ef610f446affb16e4f 100644 (file)
@@ -852,9 +852,9 @@ dependencies = [
 
 [[package]]
 name = "lsp-server"
-version = "0.4.1"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c85acaf36c53bf15da2b8b35afeea56747707261f59eb0b77229081dd72b04e"
+checksum = "69b18dfe0e4a380b872aa79d8e0ee6c3d7a9682466e84b83ad807c88b3545f79"
 dependencies = [
  "crossbeam-channel 0.5.0",
  "log",
@@ -864,9 +864,9 @@ dependencies = [
 
 [[package]]
 name = "lsp-types"
-version = "0.83.0"
+version = "0.83.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "25e0bd4b95038f2c23bda332ba0ca684e8dda765db1f9bdb63dc4c3e01f3b456"
+checksum = "c4e79f39834b97271f9f5ecec573e42c7d9c5bdbd2620b30a851054ece6aab6d"
 dependencies = [
  "base64",
  "bitflags",
index d25c4bf83747202e06f0dc9a5ec237b7061712dc..56c51486f2cfcfb1ce816c19187e217bd8bfcb56 100644 (file)
@@ -21,7 +21,7 @@ env_logger = { version = "0.8.1", default-features = false }
 itertools = "0.9.0"
 jod-thread = "0.1.0"
 log = "0.4.8"
-lsp-types = { version = "0.83.0", features = ["proposed"] }
+lsp-types = { version = "0.83.1", features = ["proposed"] }
 parking_lot = "0.11.0"
 pico-args = "0.3.1"
 oorandom = "11.1.2"
@@ -31,7 +31,7 @@ serde_json = "1.0.48"
 threadpool = "1.7.1"
 rayon = "1.5"
 mimalloc = { version = "0.1.19", default-features = false, optional = true }
-lsp-server = "0.4.0"
+lsp-server = "0.5.0"
 tracing = "0.1"
 tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
 tracing-tree = { version = "0.1.4" }
index 9a887005342ea5df5b4be54a16545aa359f8108a..c7203451ca6a700bcd9ce84318e3fb5f6ff1cb95 100644 (file)
@@ -62,6 +62,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
             prepare_provider: Some(true),
             work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
         })),
+        on_type_rename_provider: None,
         document_link_provider: None,
         color_provider: None,
         execute_command_provider: None,
index 15145415b35c00d478faa2eb405087dfae597d39..93bef5c8b48a4bf62225645cf06cfc74594bfa98 100644 (file)
@@ -55,8 +55,8 @@ fn location_naive(workspace_root: &Path, span: &DiagnosticSpan) -> lsp_types::Lo
 
     // FIXME: this doesn't handle UTF16 offsets correctly
     let range = lsp_types::Range::new(
-        lsp_types::Position::new(span.line_start as u64 - 1, span.column_start as u64 - 1),
-        lsp_types::Position::new(span.line_end as u64 - 1, span.column_end as u64 - 1),
+        lsp_types::Position::new(span.line_start as u32 - 1, span.column_start as u32 - 1),
+        lsp_types::Position::new(span.line_end as u32 - 1, span.column_end as u32 - 1),
     );
 
     lsp_types::Location { uri, range }
index 04c7ee150ae857f4ed9e2c1c0ee774be0823bf86..cf091510ffad1785f6d8a822636beaa4d8f1edae 100644 (file)
@@ -6,11 +6,11 @@
 /// client notifications.
 #[derive(Debug, Clone)]
 pub(crate) struct DocumentData {
-    pub(crate) version: Option<i64>,
+    pub(crate) version: i32,
 }
 
 impl DocumentData {
-    pub(crate) fn new(version: i64) -> Self {
-        DocumentData { version: Some(version) }
+    pub(crate) fn new(version: i32) -> Self {
+        DocumentData { version }
     }
 }
index 63c70a09d82197847938d6f1ffdaea0c84f2aafc..defe11c553004a2f2be9689d6a3dbe22de178c89 100644 (file)
@@ -263,9 +263,9 @@ pub(crate) fn file_line_endings(&self, id: FileId) -> LineEndings {
         self.vfs.read().1[&id]
     }
 
-    pub(crate) fn url_file_version(&self, url: &Url) -> Option<i64> {
+    pub(crate) fn url_file_version(&self, url: &Url) -> Option<i32> {
         let path = from_proto::vfs_path(&url).ok()?;
-        self.mem_docs.get(&path)?.version
+        Some(self.mem_docs.get(&path)?.version)
     }
 
     pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url {
index a5c65fa3e8baaf2ddc82f3d0fe969d42f9fbc623..93ac45415fbeb57dcb39658e64960cb616da933e 100644 (file)
@@ -302,7 +302,7 @@ pub enum SnippetDocumentChangeOperation {
 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct SnippetTextDocumentEdit {
-    pub text_document: lsp_types::VersionedTextDocumentIdentifier,
+    pub text_document: lsp_types::OptionalVersionedTextDocumentIdentifier,
     pub edits: Vec<SnippetTextEdit>,
 }
 
index 1d271a9d8b11405212094e4274f8b1df6968eff9..6427c73672d6fdcd311cfb32c1241e5876ff7507 100644 (file)
@@ -51,7 +51,7 @@ pub(crate) fn report_progress(
         }
         let percentage = fraction.map(|f| {
             assert!(0.0 <= f && f <= 1.0);
-            f * 100.0
+            (f * 100.0) as u32
         });
         let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));
         let work_done_progress = match state {
@@ -98,11 +98,11 @@ pub(crate) fn apply_document_changes(
     // The VFS will normalize the end of lines to `\n`.
     enum IndexValid {
         All,
-        UpToLineExclusive(u64),
+        UpToLineExclusive(u32),
     }
 
     impl IndexValid {
-        fn covers(&self, line: u64) -> bool {
+        fn covers(&self, line: u32) -> bool {
             match *self {
                 IndexValid::UpToLineExclusive(to) => to > line,
                 _ => true,
index 68a53bbcb969f0ba5f6a85dfaa19697d121c1ea0..6ea08adcead7f788f36163a2d3a1a890935dcfd4 100644 (file)
@@ -368,7 +368,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> {
                 let url = file_id_to_url(&self.vfs.read().0, file_id);
                 let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
                 let version = from_proto::vfs_path(&url)
-                    .map(|path| self.mem_docs.get(&path)?.version)
+                    .map(|path| self.mem_docs.get(&path).map(|it| it.version))
                     .unwrap_or_default();
 
                 self.send_notification::<lsp_types::notification::PublishDiagnostics>(
@@ -521,7 +521,7 @@ fn on_notification(&mut self, not: Notification) -> Result<()> {
                 let mut version = None;
                 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
                     match this.mem_docs.remove(&path) {
-                        Some(doc) => version = doc.version,
+                        Some(doc) => version = Some(doc.version),
                         None => log::error!("orphan DidCloseTextDocument: {}", path),
                     }
 
index 4bdf4bf0fad79f212a9c01f4a52e76b1600b507f..2f35425bbce39bd424a021a6b7f3150f662667a2 100644 (file)
@@ -21,9 +21,7 @@
 
 pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
     let line_col = line_index.line_col(offset);
-    let line = u64::from(line_col.line);
-    let character = u64::from(line_col.col_utf16);
-    lsp_types::Position::new(line, character)
+    lsp_types::Position::new(line_col.line, line_col.col_utf16)
 }
 
 pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Range {
@@ -278,9 +276,9 @@ pub(crate) fn signature_help(
                     label.push_str(", ");
                 }
                 first = false;
-                let start = label.len() as u64;
+                let start = label.len() as u32;
                 label.push_str(param);
-                let end = label.len() as u64;
+                let end = label.len() as u32;
                 params.push(lsp_types::ParameterInformation {
                     label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
                     documentation: None,
@@ -302,7 +300,7 @@ pub(crate) fn signature_help(
         })
     };
 
-    let active_parameter = call_info.active_parameter.map(|it| it as i64);
+    let active_parameter = call_info.active_parameter.map(|it| it as u32);
 
     let signature = lsp_types::SignatureInformation {
         label,
@@ -518,13 +516,13 @@ pub(crate) fn url_from_abs_path(path: &Path) -> lsp_types::Url {
     lsp_types::Url::parse(&url).unwrap()
 }
 
-pub(crate) fn versioned_text_document_identifier(
+pub(crate) fn optional_versioned_text_document_identifier(
     snap: &GlobalStateSnapshot,
     file_id: FileId,
-) -> lsp_types::VersionedTextDocumentIdentifier {
+) -> lsp_types::OptionalVersionedTextDocumentIdentifier {
     let url = url(snap, file_id);
     let version = snap.url_file_version(&url);
-    lsp_types::VersionedTextDocumentIdentifier { uri: url, version }
+    lsp_types::OptionalVersionedTextDocumentIdentifier { uri: url, version }
 }
 
 pub(crate) fn location(
@@ -613,7 +611,7 @@ pub(crate) fn snippet_text_document_edit(
     is_snippet: bool,
     source_file_edit: SourceFileEdit,
 ) -> Result<lsp_ext::SnippetTextDocumentEdit> {
-    let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id);
+    let text_document = optional_versioned_text_document_identifier(snap, source_file_edit.file_id);
     let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?;
     let line_endings = snap.file_line_endings(source_file_edit.file_id);
     let edits = source_file_edit
index b210b98f0d5cf598f77733f3068f66d27fee3518..456125789397811b4282f132f1f395797321660f 100644 (file)
@@ -108,7 +108,7 @@ pub(crate) fn project(fixture: &str) -> Server {
 }
 
 pub(crate) struct Server {
-    req_id: Cell<u64>,
+    req_id: Cell<i32>,
     messages: RefCell<Vec<Message>>,
     _thread: jod_thread::JoinHandle<()>,
     client: Connection,
@@ -165,7 +165,7 @@ pub(crate) fn send_request<R>(&self, params: R::Params) -> Value
         R::Params: Serialize,
     {
         let id = self.req_id.get();
-        self.req_id.set(id + 1);
+        self.req_id.set(id.wrapping_add(1));
 
         let r = Request::new(id.into(), R::METHOD.to_string(), params);
         self.send_request_(r)
index db9727bee42aeeb3a543d378da897e79d334b415..8c01db07c8496519960288f4947623b938a2a6ab 100644 (file)
@@ -1,5 +1,5 @@
 <!---
-lsp_ext.rs hash: 9d5daed5b25dc4f6
+lsp_ext.rs hash: 203fdf79b21b5987
 
 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:
@@ -45,7 +45,7 @@ interface SnippetTextEdit extends TextEdit {
 
 ```typescript
 export interface TextDocumentEdit {
-       textDocument: VersionedTextDocumentIdentifier;
+       textDocument: OptionalVersionedTextDocumentIdentifier;
        edits: (TextEdit | SnippetTextEdit)[];
 }
 ```