aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkjeremy <[email protected]>2020-11-16 20:10:13 +0000
committerkjeremy <[email protected]>2020-11-16 20:10:13 +0000
commit233fdb12cee6aa160579cfded171fa4c2f82b29c (patch)
treee8a71e22de514f268501b62694aeb0343f355eb8
parent0a658c4a973d934d622957a6fb03916271496385 (diff)
Latest LSP 3.16 protocol
Pulls in https://github.com/gluon-lang/lsp-types/pull/186
-rw-r--r--Cargo.lock8
-rw-r--r--crates/rust-analyzer/Cargo.toml4
-rw-r--r--crates/rust-analyzer/src/caps.rs1
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs4
-rw-r--r--crates/rust-analyzer/src/document.rs6
-rw-r--r--crates/rust-analyzer/src/global_state.rs4
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs2
-rw-r--r--crates/rust-analyzer/src/lsp_utils.rs6
-rw-r--r--crates/rust-analyzer/src/main_loop.rs4
-rw-r--r--crates/rust-analyzer/src/to_proto.rs18
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/support.rs4
-rw-r--r--docs/dev/lsp-extensions.md4
12 files changed, 32 insertions, 33 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 715a80978..09215a37a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -852,9 +852,9 @@ dependencies = [
852 852
853[[package]] 853[[package]]
854name = "lsp-server" 854name = "lsp-server"
855version = "0.4.1" 855version = "0.5.0"
856source = "registry+https://github.com/rust-lang/crates.io-index" 856source = "registry+https://github.com/rust-lang/crates.io-index"
857checksum = "9c85acaf36c53bf15da2b8b35afeea56747707261f59eb0b77229081dd72b04e" 857checksum = "69b18dfe0e4a380b872aa79d8e0ee6c3d7a9682466e84b83ad807c88b3545f79"
858dependencies = [ 858dependencies = [
859 "crossbeam-channel 0.5.0", 859 "crossbeam-channel 0.5.0",
860 "log", 860 "log",
@@ -864,9 +864,9 @@ dependencies = [
864 864
865[[package]] 865[[package]]
866name = "lsp-types" 866name = "lsp-types"
867version = "0.83.0" 867version = "0.83.1"
868source = "registry+https://github.com/rust-lang/crates.io-index" 868source = "registry+https://github.com/rust-lang/crates.io-index"
869checksum = "25e0bd4b95038f2c23bda332ba0ca684e8dda765db1f9bdb63dc4c3e01f3b456" 869checksum = "c4e79f39834b97271f9f5ecec573e42c7d9c5bdbd2620b30a851054ece6aab6d"
870dependencies = [ 870dependencies = [
871 "base64", 871 "base64",
872 "bitflags", 872 "bitflags",
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index d25c4bf83..56c51486f 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -21,7 +21,7 @@ env_logger = { version = "0.8.1", default-features = false }
21itertools = "0.9.0" 21itertools = "0.9.0"
22jod-thread = "0.1.0" 22jod-thread = "0.1.0"
23log = "0.4.8" 23log = "0.4.8"
24lsp-types = { version = "0.83.0", features = ["proposed"] } 24lsp-types = { version = "0.83.1", features = ["proposed"] }
25parking_lot = "0.11.0" 25parking_lot = "0.11.0"
26pico-args = "0.3.1" 26pico-args = "0.3.1"
27oorandom = "11.1.2" 27oorandom = "11.1.2"
@@ -31,7 +31,7 @@ serde_json = "1.0.48"
31threadpool = "1.7.1" 31threadpool = "1.7.1"
32rayon = "1.5" 32rayon = "1.5"
33mimalloc = { version = "0.1.19", default-features = false, optional = true } 33mimalloc = { version = "0.1.19", default-features = false, optional = true }
34lsp-server = "0.4.0" 34lsp-server = "0.5.0"
35tracing = "0.1" 35tracing = "0.1"
36tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } 36tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
37tracing-tree = { version = "0.1.4" } 37tracing-tree = { version = "0.1.4" }
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index 9a8870053..c7203451c 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -62,6 +62,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
62 prepare_provider: Some(true), 62 prepare_provider: Some(true),
63 work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None }, 63 work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
64 })), 64 })),
65 on_type_rename_provider: None,
65 document_link_provider: None, 66 document_link_provider: None,
66 color_provider: None, 67 color_provider: None,
67 execute_command_provider: None, 68 execute_command_provider: None,
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index 15145415b..93bef5c8b 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -55,8 +55,8 @@ fn location_naive(workspace_root: &Path, span: &DiagnosticSpan) -> lsp_types::Lo
55 55
56 // FIXME: this doesn't handle UTF16 offsets correctly 56 // FIXME: this doesn't handle UTF16 offsets correctly
57 let range = lsp_types::Range::new( 57 let range = lsp_types::Range::new(
58 lsp_types::Position::new(span.line_start as u64 - 1, span.column_start as u64 - 1), 58 lsp_types::Position::new(span.line_start as u32 - 1, span.column_start as u32 - 1),
59 lsp_types::Position::new(span.line_end as u64 - 1, span.column_end as u64 - 1), 59 lsp_types::Position::new(span.line_end as u32 - 1, span.column_end as u32 - 1),
60 ); 60 );
61 61
62 lsp_types::Location { uri, range } 62 lsp_types::Location { uri, range }
diff --git a/crates/rust-analyzer/src/document.rs b/crates/rust-analyzer/src/document.rs
index 04c7ee150..cf091510f 100644
--- a/crates/rust-analyzer/src/document.rs
+++ b/crates/rust-analyzer/src/document.rs
@@ -6,11 +6,11 @@
6/// client notifications. 6/// client notifications.
7#[derive(Debug, Clone)] 7#[derive(Debug, Clone)]
8pub(crate) struct DocumentData { 8pub(crate) struct DocumentData {
9 pub(crate) version: Option<i64>, 9 pub(crate) version: i32,
10} 10}
11 11
12impl DocumentData { 12impl DocumentData {
13 pub(crate) fn new(version: i64) -> Self { 13 pub(crate) fn new(version: i32) -> Self {
14 DocumentData { version: Some(version) } 14 DocumentData { version }
15 } 15 }
16} 16}
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 63c70a09d..defe11c55 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -263,9 +263,9 @@ impl GlobalStateSnapshot {
263 self.vfs.read().1[&id] 263 self.vfs.read().1[&id]
264 } 264 }
265 265
266 pub(crate) fn url_file_version(&self, url: &Url) -> Option<i64> { 266 pub(crate) fn url_file_version(&self, url: &Url) -> Option<i32> {
267 let path = from_proto::vfs_path(&url).ok()?; 267 let path = from_proto::vfs_path(&url).ok()?;
268 self.mem_docs.get(&path)?.version 268 Some(self.mem_docs.get(&path)?.version)
269 } 269 }
270 270
271 pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url { 271 pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url {
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index a5c65fa3e..93ac45415 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -302,7 +302,7 @@ pub enum SnippetDocumentChangeOperation {
302#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 302#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
303#[serde(rename_all = "camelCase")] 303#[serde(rename_all = "camelCase")]
304pub struct SnippetTextDocumentEdit { 304pub struct SnippetTextDocumentEdit {
305 pub text_document: lsp_types::VersionedTextDocumentIdentifier, 305 pub text_document: lsp_types::OptionalVersionedTextDocumentIdentifier,
306 pub edits: Vec<SnippetTextEdit>, 306 pub edits: Vec<SnippetTextEdit>,
307} 307}
308 308
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs
index 1d271a9d8..6427c7367 100644
--- a/crates/rust-analyzer/src/lsp_utils.rs
+++ b/crates/rust-analyzer/src/lsp_utils.rs
@@ -51,7 +51,7 @@ impl GlobalState {
51 } 51 }
52 let percentage = fraction.map(|f| { 52 let percentage = fraction.map(|f| {
53 assert!(0.0 <= f && f <= 1.0); 53 assert!(0.0 <= f && f <= 1.0);
54 f * 100.0 54 (f * 100.0) as u32
55 }); 55 });
56 let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title)); 56 let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));
57 let work_done_progress = match state { 57 let work_done_progress = match state {
@@ -98,11 +98,11 @@ pub(crate) fn apply_document_changes(
98 // The VFS will normalize the end of lines to `\n`. 98 // The VFS will normalize the end of lines to `\n`.
99 enum IndexValid { 99 enum IndexValid {
100 All, 100 All,
101 UpToLineExclusive(u64), 101 UpToLineExclusive(u32),
102 } 102 }
103 103
104 impl IndexValid { 104 impl IndexValid {
105 fn covers(&self, line: u64) -> bool { 105 fn covers(&self, line: u32) -> bool {
106 match *self { 106 match *self {
107 IndexValid::UpToLineExclusive(to) => to > line, 107 IndexValid::UpToLineExclusive(to) => to > line,
108 _ => true, 108 _ => true,
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 68a53bbcb..6ea08adce 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -368,7 +368,7 @@ impl GlobalState {
368 let url = file_id_to_url(&self.vfs.read().0, file_id); 368 let url = file_id_to_url(&self.vfs.read().0, file_id);
369 let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect(); 369 let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
370 let version = from_proto::vfs_path(&url) 370 let version = from_proto::vfs_path(&url)
371 .map(|path| self.mem_docs.get(&path)?.version) 371 .map(|path| self.mem_docs.get(&path).map(|it| it.version))
372 .unwrap_or_default(); 372 .unwrap_or_default();
373 373
374 self.send_notification::<lsp_types::notification::PublishDiagnostics>( 374 self.send_notification::<lsp_types::notification::PublishDiagnostics>(
@@ -521,7 +521,7 @@ impl GlobalState {
521 let mut version = None; 521 let mut version = None;
522 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) { 522 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
523 match this.mem_docs.remove(&path) { 523 match this.mem_docs.remove(&path) {
524 Some(doc) => version = doc.version, 524 Some(doc) => version = Some(doc.version),
525 None => log::error!("orphan DidCloseTextDocument: {}", path), 525 None => log::error!("orphan DidCloseTextDocument: {}", path),
526 } 526 }
527 527
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 4bdf4bf0f..2f35425bb 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -21,9 +21,7 @@ use crate::{
21 21
22pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position { 22pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
23 let line_col = line_index.line_col(offset); 23 let line_col = line_index.line_col(offset);
24 let line = u64::from(line_col.line); 24 lsp_types::Position::new(line_col.line, line_col.col_utf16)
25 let character = u64::from(line_col.col_utf16);
26 lsp_types::Position::new(line, character)
27} 25}
28 26
29pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Range { 27pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Range {
@@ -278,9 +276,9 @@ pub(crate) fn signature_help(
278 label.push_str(", "); 276 label.push_str(", ");
279 } 277 }
280 first = false; 278 first = false;
281 let start = label.len() as u64; 279 let start = label.len() as u32;
282 label.push_str(param); 280 label.push_str(param);
283 let end = label.len() as u64; 281 let end = label.len() as u32;
284 params.push(lsp_types::ParameterInformation { 282 params.push(lsp_types::ParameterInformation {
285 label: lsp_types::ParameterLabel::LabelOffsets([start, end]), 283 label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
286 documentation: None, 284 documentation: None,
@@ -302,7 +300,7 @@ pub(crate) fn signature_help(
302 }) 300 })
303 }; 301 };
304 302
305 let active_parameter = call_info.active_parameter.map(|it| it as i64); 303 let active_parameter = call_info.active_parameter.map(|it| it as u32);
306 304
307 let signature = lsp_types::SignatureInformation { 305 let signature = lsp_types::SignatureInformation {
308 label, 306 label,
@@ -518,13 +516,13 @@ pub(crate) fn url_from_abs_path(path: &Path) -> lsp_types::Url {
518 lsp_types::Url::parse(&url).unwrap() 516 lsp_types::Url::parse(&url).unwrap()
519} 517}
520 518
521pub(crate) fn versioned_text_document_identifier( 519pub(crate) fn optional_versioned_text_document_identifier(
522 snap: &GlobalStateSnapshot, 520 snap: &GlobalStateSnapshot,
523 file_id: FileId, 521 file_id: FileId,
524) -> lsp_types::VersionedTextDocumentIdentifier { 522) -> lsp_types::OptionalVersionedTextDocumentIdentifier {
525 let url = url(snap, file_id); 523 let url = url(snap, file_id);
526 let version = snap.url_file_version(&url); 524 let version = snap.url_file_version(&url);
527 lsp_types::VersionedTextDocumentIdentifier { uri: url, version } 525 lsp_types::OptionalVersionedTextDocumentIdentifier { uri: url, version }
528} 526}
529 527
530pub(crate) fn location( 528pub(crate) fn location(
@@ -613,7 +611,7 @@ pub(crate) fn snippet_text_document_edit(
613 is_snippet: bool, 611 is_snippet: bool,
614 source_file_edit: SourceFileEdit, 612 source_file_edit: SourceFileEdit,
615) -> Result<lsp_ext::SnippetTextDocumentEdit> { 613) -> Result<lsp_ext::SnippetTextDocumentEdit> {
616 let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id); 614 let text_document = optional_versioned_text_document_identifier(snap, source_file_edit.file_id);
617 let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?; 615 let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?;
618 let line_endings = snap.file_line_endings(source_file_edit.file_id); 616 let line_endings = snap.file_line_endings(source_file_edit.file_id);
619 let edits = source_file_edit 617 let edits = source_file_edit
diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs
index b210b98f0..456125789 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/support.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs
@@ -108,7 +108,7 @@ pub(crate) fn project(fixture: &str) -> Server {
108} 108}
109 109
110pub(crate) struct Server { 110pub(crate) struct Server {
111 req_id: Cell<u64>, 111 req_id: Cell<i32>,
112 messages: RefCell<Vec<Message>>, 112 messages: RefCell<Vec<Message>>,
113 _thread: jod_thread::JoinHandle<()>, 113 _thread: jod_thread::JoinHandle<()>,
114 client: Connection, 114 client: Connection,
@@ -165,7 +165,7 @@ impl Server {
165 R::Params: Serialize, 165 R::Params: Serialize,
166 { 166 {
167 let id = self.req_id.get(); 167 let id = self.req_id.get();
168 self.req_id.set(id + 1); 168 self.req_id.set(id.wrapping_add(1));
169 169
170 let r = Request::new(id.into(), R::METHOD.to_string(), params); 170 let r = Request::new(id.into(), R::METHOD.to_string(), params);
171 self.send_request_(r) 171 self.send_request_(r)
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index db9727bee..8c01db07c 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,5 +1,5 @@
1<!--- 1<!---
2lsp_ext.rs hash: 9d5daed5b25dc4f6 2lsp_ext.rs hash: 203fdf79b21b5987
3 3
4If you need to change the above hash to make the test pass, please check if you 4If you need to change the above hash to make the test pass, please check if you
5need to adjust this doc as well and ping this issue: 5need to adjust this doc as well and ping this issue:
@@ -45,7 +45,7 @@ interface SnippetTextEdit extends TextEdit {
45 45
46```typescript 46```typescript
47export interface TextDocumentEdit { 47export interface TextDocumentEdit {
48 textDocument: VersionedTextDocumentIdentifier; 48 textDocument: OptionalVersionedTextDocumentIdentifier;
49 edits: (TextEdit | SnippetTextEdit)[]; 49 edits: (TextEdit | SnippetTextEdit)[];
50} 50}
51``` 51```