Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
The main motiviation is to get `crossbeam-channel` at at least 0.5.1 as
this appears to fix a memory like[1] which is probably the root-cause of
our own memory issues[2].

This also included some changes to the LSP type-system as a few more
changes in the LSP protocol are now incorporated, such as a
clarification that numbers are usually unsigned 32bit rather than
64bit[3].

[1] https://github.com/crossbeam-rs/crossbeam/blob/crossbeam-channel-0.5.1/crossbeam-channel/CHANGELOG.md#version-051
[2] nix-community#33
[3] gluon-lang/lsp-types@f654090
  • Loading branch information
Ma27 committed Aug 31, 2021
1 parent 3cd3f0b commit 4909cb1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 66 deletions.
64 changes: 15 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ name = "rnix-lsp"
version = "0.1.0"

[dependencies]
dirs = "2.0.2"
env_logger = "0.7.1"
dirs = "3.0.2"
env_logger = "0.9.0"
lazy_static = "1.4"
libc = "0.2.66"
log = "0.4.8"
lsp-server = "0.3.1"
lsp-types = { version = "0.68.1", features = ["proposed"] }
lsp-server = "0.5.2"
lsp-types = { version = "0.89.2", features = ["proposed"] }
nixpkgs-fmt = "1.2.0"
regex = "1"
rnix = "0.9.0"
Expand Down
24 changes: 13 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestI
use lsp_types::{
notification::{Notification as _, *},
request::{Request as RequestTrait, *},
OneOf,
*,
};
use rnix::{
Expand Down Expand Up @@ -75,13 +76,13 @@ fn real_main() -> Result<(), Error> {
completion_provider: Some(CompletionOptions {
..CompletionOptions::default()
}),
definition_provider: Some(true),
document_formatting_provider: Some(true),
definition_provider: Some(OneOf::Left(true)),
document_formatting_provider: Some(OneOf::Left(true)),
document_link_provider: Some(DocumentLinkOptions {
resolve_provider: Some(false),
work_done_progress_options: WorkDoneProgressOptions::default(),
}),
rename_provider: Some(RenameProviderCapability::Simple(true)),
rename_provider: Some(OneOf::Left(true)),
selection_range_provider: Some(SelectionRangeProviderCapability::Simple(true)),
..ServerCapabilities::default()
})
Expand Down Expand Up @@ -169,7 +170,7 @@ impl App {
}
let mut req = Some(req);
if let Some((id, params)) = cast::<GotoDefinition>(&mut req) {
if let Some(pos) = self.lookup_definition(params) {
if let Some(pos) = self.lookup_definition(params.text_document_position_params) {
self.reply(Response::new_ok(id, pos));
} else {
self.reply(Response::new_ok(id, ()));
Expand Down Expand Up @@ -327,10 +328,10 @@ impl App {
.documentation
.map(|x| lsp_types::Documentation::String(x)),
deprecated: Some(data.deprecated),
text_edit: Some(TextEdit {
text_edit: Some(CompletionTextEdit::Edit(TextEdit {
range: utils::range(content, node.node().text_range()),
new_text: var.clone(),
}),
})),
detail: Some(det),
..CompletionItem::default()
});
Expand Down Expand Up @@ -437,20 +438,21 @@ impl App {

// Nix doesn't have multi-line links
let start_pos = Position {
line: line_num as u64,
character: (next_link_pos - cur_line_start) as u64,
line: line_num as u32,
character: (next_link_pos - cur_line_start) as u32,
};
let end_pos = Position {
line: line_num as u64,
character: (usize::from(range.end()) - cur_line_start) as u64,
line: line_num as u32,
character: (usize::from(range.end()) - cur_line_start) as u32,
};
let lsp_range = Range {
start: start_pos,
end: end_pos,
};

lsp_links.push(DocumentLink {
target: url,
target: Some(url),
data: None,
range: lsp_range,
tooltip: None,
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ pub fn lookup_pos(code: &str, pos: Position) -> Option<usize> {
pub fn offset_to_pos(code: &str, offset: usize) -> Position {
let start_of_line = code[..offset].rfind('\n').map_or(0, |n| n + 1);
Position {
line: code[..start_of_line].chars().filter(|&c| c == '\n').count() as u64,
line: code[..start_of_line].chars().filter(|&c| c == '\n').count() as u32,
character: code[start_of_line..offset]
.chars()
.map(|c| c.len_utf16() as u64)
.map(|c| c.len_utf16() as u32)
.sum(),
}
}
Expand Down

0 comments on commit 4909cb1

Please # to comment.