Skip to content

Commit 581a033

Browse files
authored
Update lsp types (#1180)
* Bump lsp-types to 0.85 * Bump lsp-types to 0.86 * Fix ci dependency installation * Fix tests * Fix lint issues
1 parent 8384926 commit 581a033

File tree

9 files changed

+131
-112
lines changed

9 files changed

+131
-112
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install other dependencies
3030
run: |
3131
sudo apt-get update
32-
sudo apt-get install --yes --no-install-recommends neovim curl git python3-pip python3-pytest mypy flake8 npm make
32+
sudo apt-get install --yes --no-install-recommends neovim curl git python3-pip python3-pytest mypy flake8 nodejs-dev node-gyp libssl1.0 npm make
3333
sudo apt-get clean
3434
sudo rm -rf /var/lib/apt/lists/*
3535
python3 -m pip install neovim vim-vint

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ serde_json = "1"
2828
json-patch = "0.2"
2929
crossbeam = "0.7.3"
3030
jsonrpc-core = "15"
31-
lsp-types = { version = "0.83", features = ["proposed"] }
31+
lsp-types = { version = "0.86", features = ["proposed"] }
3232
url = "2"
3333
pathdiff = "0"
3434
diff = "0"

src/language_server_protocol.rs

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@ use itertools::Itertools;
2121
use jsonrpc_core::Value;
2222
use log::{debug, error, info, warn};
2323
use lsp_types::{
24-
notification::Notification, request::Request, ApplyWorkspaceEditParams,
25-
ApplyWorkspaceEditResponse, ClientCapabilities, ClientInfo, CodeAction, CodeActionCapability,
26-
CodeActionContext, CodeActionKind, CodeActionKindLiteralSupport, CodeActionLiteralSupport,
27-
CodeActionOrCommand, CodeActionParams, CodeActionResponse, CodeLens, Command,
28-
CompletionCapability, CompletionItem, CompletionItemCapability, CompletionResponse,
29-
CompletionTextEdit, ConfigurationParams, Diagnostic, DiagnosticSeverity,
30-
DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams,
24+
notification::Notification, request::Request, AnnotatedTextEdit, ApplyWorkspaceEditParams,
25+
ApplyWorkspaceEditResponse, ClientCapabilities, ClientInfo, CodeAction,
26+
CodeActionClientCapabilities, CodeActionContext, CodeActionKind, CodeActionKindLiteralSupport,
27+
CodeActionLiteralSupport, CodeActionOrCommand, CodeActionParams, CodeActionResponse, CodeLens,
28+
CodeLensClientCapabilities, Command, CompletionClientCapabilities, CompletionItem,
29+
CompletionItemCapability, CompletionResponse, CompletionTextEdit, ConfigurationParams,
30+
Diagnostic, DiagnosticSeverity, DidChangeConfigurationParams, DidChangeTextDocumentParams,
31+
DidChangeWatchedFilesClientCapabilities, DidChangeWatchedFilesParams,
3132
DidChangeWatchedFilesRegistrationOptions, DidCloseTextDocumentParams,
3233
DidOpenTextDocumentParams, DidSaveTextDocumentParams, DocumentChangeOperation, DocumentChanges,
33-
DocumentFormattingParams, DocumentHighlight, DocumentHighlightKind,
34-
DocumentRangeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, Documentation,
35-
ExecuteCommandParams, FormattingOptions, GenericCapability, GotoCapability,
36-
GotoDefinitionResponse, Hover, HoverCapability, InitializeParams, InitializeResult,
34+
DocumentColorClientCapabilities, DocumentFormattingParams, DocumentHighlight,
35+
DocumentHighlightKind, DocumentRangeFormattingParams, DocumentSymbolParams,
36+
DocumentSymbolResponse, Documentation, ExecuteCommandParams, FormattingOptions, GotoCapability,
37+
GotoDefinitionResponse, Hover, HoverClientCapabilities, InitializeParams, InitializeResult,
3738
InitializedParams, Location, LogMessageParams, MessageType, NumberOrString,
3839
ParameterInformation, ParameterInformationSettings, PartialResultParams, Position,
3940
ProgressParams, ProgressParamsValue, PublishDiagnosticsClientCapabilities,
4041
PublishDiagnosticsParams, Range, ReferenceContext, RegistrationParams, RenameParams,
4142
ResourceOp, SemanticHighlightingClientCapability, SemanticHighlightingParams,
42-
ShowMessageParams, ShowMessageRequestParams, SignatureHelp, SignatureHelpCapability,
43+
ShowMessageParams, ShowMessageRequestParams, SignatureHelp, SignatureHelpClientCapabilities,
4344
SignatureInformationSettings, SymbolInformation, TextDocumentClientCapabilities,
4445
TextDocumentContentChangeEvent, TextDocumentIdentifier, TextDocumentItem,
4546
TextDocumentPositionParams, TextEdit, UnregistrationParams, VersionedTextDocumentIdentifier,
@@ -226,7 +227,14 @@ impl LanguageClient {
226227
}
227228
} else if let Some(ref changes) = edit.changes {
228229
for (uri, edits) in changes {
229-
position = self.apply_text_edits(&uri.filepath()?, edits, position)?;
230+
position = self.apply_text_edits(
231+
&uri.filepath()?,
232+
&edits
233+
.iter()
234+
.map(|e| lsp_types::OneOf::Left(e.clone()))
235+
.collect::<Vec<lsp_types::OneOf<TextEdit, AnnotatedTextEdit>>>(),
236+
position,
237+
)?;
230238
}
231239
}
232240
self.edit(&None, &filename)?;
@@ -298,7 +306,7 @@ impl LanguageClient {
298306
fn apply_text_edits<P: AsRef<Path> + std::fmt::Debug>(
299307
&self,
300308
path: P,
301-
edits: &[TextEdit],
309+
edits: &[lsp_types::OneOf<TextEdit, AnnotatedTextEdit>],
302310
position: Position,
303311
) -> Result<Position> {
304312
if edits.is_empty() {
@@ -313,7 +321,13 @@ impl LanguageClient {
313321
// same order the server sent it, and so that a delete/replace (according to the LSP spec,
314322
// there can only be one per start position and it must be after the inserts) will work on
315323
// the original document, not on the just-inserted text.
316-
edits.sort_by_key(|edit| (edit.range.start.line, edit.range.start.character));
324+
edits.sort_by_key(|edit| match edit {
325+
lsp_types::OneOf::Left(edit) => (edit.range.start.line, edit.range.start.character),
326+
lsp_types::OneOf::Right(ae) => (
327+
ae.text_edit.range.start.line,
328+
ae.text_edit.range.start.character,
329+
),
330+
});
317331
edits.reverse();
318332

319333
self.edit(&None, path)?;
@@ -713,7 +727,7 @@ impl LanguageClient {
713727
Ok(())
714728
}
715729

716-
pub fn get_line(&self, path: impl AsRef<Path>, line: u64) -> Result<String> {
730+
pub fn get_line(&self, path: impl AsRef<Path>, line: u32) -> Result<String> {
717731
let value: Value = self.vim()?.rpcclient.call(
718732
"getbufline",
719733
json!([path.as_ref().to_string_lossy(), line + 1]),
@@ -725,7 +739,7 @@ impl LanguageClient {
725739
let reader = BufReader::new(File::open(path)?);
726740
text = reader
727741
.lines()
728-
.nth(line.to_usize()?)
742+
.nth(line as usize)
729743
.ok_or_else(|| anyhow!("Failed to get line! line: {}", line))??;
730744
}
731745

@@ -875,17 +889,17 @@ impl LanguageClient {
875889
name: "LanguageClient-neovim".into(),
876890
version: Some(self.version()),
877891
}),
878-
process_id: Some(u64::from(std::process::id())),
892+
process_id: Some(std::process::id()),
879893
/* deprecated in lsp types, but can't initialize without it */
880894
root_path: Some(root.clone()),
881895
root_uri: Some(root.to_url()?),
882896
initialization_options: initialization_options.clone(),
883897
capabilities: ClientCapabilities {
884898
text_document: Some(TextDocumentClientCapabilities {
885-
color_provider: Some(GenericCapability {
899+
color_provider: Some(DocumentColorClientCapabilities {
886900
dynamic_registration: Some(false),
887901
}),
888-
completion: Some(CompletionCapability {
902+
completion: Some(CompletionClientCapabilities {
889903
completion_item: Some(CompletionItemCapability {
890904
snippet_support: Some(has_snippet_support),
891905
documentation_format: preferred_markup_kind.clone(),
@@ -896,9 +910,9 @@ impl LanguageClient {
896910
insert_replace_support: Some(false),
897911
..CompletionItemCapability::default()
898912
}),
899-
..CompletionCapability::default()
913+
..CompletionClientCapabilities::default()
900914
}),
901-
code_action: Some(CodeActionCapability {
915+
code_action: Some(CodeActionClientCapabilities {
902916
code_action_literal_support: Some(CodeActionLiteralSupport {
903917
code_action_kind: CodeActionKindLiteralSupport {
904918
value_set: [
@@ -915,17 +929,17 @@ impl LanguageClient {
915929
.collect(),
916930
},
917931
}),
918-
..CodeActionCapability::default()
932+
..CodeActionClientCapabilities::default()
919933
}),
920-
signature_help: Some(SignatureHelpCapability {
934+
signature_help: Some(SignatureHelpClientCapabilities {
921935
signature_information: Some(SignatureInformationSettings {
922936
active_parameter_support: None,
923937
documentation_format: preferred_markup_kind.clone(),
924938
parameter_information: Some(ParameterInformationSettings {
925939
label_offset_support: Some(true),
926940
}),
927941
}),
928-
..SignatureHelpCapability::default()
942+
..SignatureHelpClientCapabilities::default()
929943
}),
930944
declaration: Some(GotoCapability {
931945
link_support: Some(true),
@@ -947,24 +961,24 @@ impl LanguageClient {
947961
related_information: Some(true),
948962
..PublishDiagnosticsClientCapabilities::default()
949963
}),
950-
code_lens: Some(GenericCapability {
964+
code_lens: Some(CodeLensClientCapabilities {
951965
dynamic_registration: Some(true),
952966
}),
953967
semantic_highlighting_capabilities: Some(
954968
SemanticHighlightingClientCapability {
955969
semantic_highlighting: true,
956970
},
957971
),
958-
hover: Some(HoverCapability {
972+
hover: Some(HoverClientCapabilities {
959973
content_format: preferred_markup_kind,
960-
..HoverCapability::default()
974+
..HoverClientCapabilities::default()
961975
}),
962976
..TextDocumentClientCapabilities::default()
963977
}),
964978
workspace: Some(WorkspaceClientCapabilities {
965979
apply_edit: Some(true),
966980
configuration: Some(true),
967-
did_change_watched_files: Some(GenericCapability {
981+
did_change_watched_files: Some(DidChangeWatchedFilesClientCapabilities {
968982
dynamic_registration: Some(true),
969983
}),
970984
..WorkspaceClientCapabilities::default()
@@ -973,6 +987,7 @@ impl LanguageClient {
973987
},
974988
trace: Some(trace),
975989
workspace_folders: None,
990+
locale: None,
976991
},
977992
)?;
978993

@@ -1524,6 +1539,7 @@ impl LanguageClient {
15241539
let text_edits = text_edits.unwrap_or_default();
15251540
let edit = lsp_types::WorkspaceEdit {
15261541
changes: Some(hashmap! {filename.to_url()? => text_edits}),
1542+
change_annotations: None,
15271543
document_changes: None,
15281544
};
15291545
self.apply_workspace_edit(&edit)?;
@@ -1576,6 +1592,7 @@ impl LanguageClient {
15761592
let text_edits = text_edits.unwrap_or_default();
15771593
let edit = lsp_types::WorkspaceEdit {
15781594
changes: Some(hashmap! {filename.to_url()? => text_edits}),
1595+
change_annotations: None,
15791596
document_changes: None,
15801597
};
15811598
self.apply_workspace_edit(&edit)?;
@@ -1774,6 +1791,8 @@ impl LanguageClient {
17741791
self.apply_workspace_edit(&params.edit)?;
17751792
Ok(serde_json::to_value(ApplyWorkspaceEditResponse {
17761793
applied: true,
1794+
failure_reason: None,
1795+
failed_change: None,
17771796
})?)
17781797
}
17791798

@@ -2052,7 +2071,7 @@ impl LanguageClient {
20522071
DidChangeTextDocumentParams {
20532072
text_document: VersionedTextDocumentIdentifier {
20542073
uri: filename.to_url()?,
2055-
version: Some(version),
2074+
version,
20562075
},
20572076
content_changes: vec![TextDocumentContentChangeEvent {
20582077
range: None,
@@ -2291,7 +2310,7 @@ impl LanguageClient {
22912310
* single line so simply clear between the first and last line to
22922311
* ensure no highlights are left dangling
22932312
*/
2294-
let mut clear_region: Option<(u64, u64)> = None;
2313+
let mut clear_region: Option<(u32, u32)> = None;
22952314
let mut highlights = Vec::with_capacity(semantic_hl_state.symbols.len());
22962315

22972316
for line in &semantic_hl_state.symbols {
@@ -2303,9 +2322,9 @@ impl LanguageClient {
23032322

23042323
if let Some(Some(group)) = hl_table.get(token.scope as usize) {
23052324
highlights.push(Highlight {
2306-
line: line.line as u64,
2307-
character_start: token.character as u64,
2308-
character_end: token.character as u64 + token.length as u64,
2325+
line: line.line as u32,
2326+
character_start: token.character,
2327+
character_end: token.character + token.length as u32,
23092328
group: group.clone(),
23102329
text: String::new(),
23112330
});
@@ -2314,10 +2333,10 @@ impl LanguageClient {
23142333

23152334
match clear_region {
23162335
Some((begin, _)) => {
2317-
clear_region = Some((begin, line.line as u64 + 1));
2336+
clear_region = Some((begin, line.line as u32 + 1));
23182337
}
23192338
None => {
2320-
clear_region = Some((line.line as u64, line.line as u64 + 1));
2339+
clear_region = Some((line.line as u32, line.line as u32 + 1));
23212340
}
23222341
}
23232342
}
@@ -2720,7 +2739,7 @@ impl LanguageClient {
27202739
CompletionResponse::List(list) => list.items,
27212740
};
27222741

2723-
let complete_position: Option<u64> = try_get("complete_position", params)?;
2742+
let complete_position: Option<u32> = try_get("complete_position", params)?;
27242743

27252744
let matches: Result<Vec<VimCompleteItem>> = matches
27262745
.iter()
@@ -3161,7 +3180,7 @@ impl LanguageClient {
31613180
// Check that we're not doing anything stupid before going ahead with this.
31623181
let mut edit = edit;
31633182
edit.range.end.character =
3164-
edit.range.start.character + completed_item.word.len() as u64;
3183+
edit.range.start.character + completed_item.word.len() as u32;
31653184
if edit.range.end != position || edit.range.start.line != edit.range.end.line {
31663185
return Ok(());
31673186
}
@@ -3179,7 +3198,14 @@ impl LanguageClient {
31793198
return Ok(());
31803199
}
31813200

3182-
let position = self.apply_text_edits(filename, &edits, position)?;
3201+
let position = self.apply_text_edits(
3202+
filename,
3203+
&edits
3204+
.into_iter()
3205+
.map(lsp_types::OneOf::Left)
3206+
.collect::<Vec<lsp_types::OneOf<TextEdit, AnnotatedTextEdit>>>(),
3207+
position,
3208+
)?;
31833209
self.vim()?
31843210
.cursor(position.line + 1, position.character + 1)
31853211
}
@@ -3218,12 +3244,12 @@ impl LanguageClient {
32183244
let line = tokens_iter
32193245
.next()
32203246
.ok_or_else(|| anyhow!("Failed to get line! tokens: {:?}", tokens))?
3221-
.to_int()?
3247+
.parse::<u32>()?
32223248
- 1;
32233249
let character = tokens_iter
32243250
.next()
32253251
.ok_or_else(|| anyhow!("Failed to get character! tokens: {:?}", tokens))?
3226-
.to_int()?
3252+
.parse::<u32>()?
32273253
- 1;
32283254

32293255
self.edit(&None, &filename)?;

src/sign.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
55
pub struct Sign {
66
pub id: u64,
77
/// line number. 0-based.
8-
pub line: u64,
8+
pub line: u32,
99
pub name: String,
1010
}
1111

@@ -14,7 +14,7 @@ impl From<&Diagnostic> for Sign {
1414
let line = diagnostic.range.start.line;
1515
let severity = diagnostic.severity.unwrap_or(DiagnosticSeverity::Hint);
1616
let name = format!("LanguageClient{:?}", severity);
17-
let id = 75_000 + line * DiagnosticSeverity::Hint as u64 + severity as u64;
17+
let id = 75_000 + line as u64 * DiagnosticSeverity::Hint as u64 + severity as u64;
1818

1919
Sign { id, line, name }
2020
}

0 commit comments

Comments
 (0)