Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Upgrade to tower-lsp 0.13.0 #61

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ serde_json = { version = "1.0", optional = true }
sled = "0.34.0"
thiserror = "1.0.14"
tokio = { version = "0.2.13", features = ["io-std", "macros", "sync", "time"] }
tower-lsp = "0.12.0"
tower-lsp = "0.13.0"
tower-test = { version = "0.3.0", optional = true }
tree-sitter = "0.16.1"
uuid = { version = "0.8.1", features = ["v4"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/server/src/lsp/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl LanguageServer for Server {
}

async fn initialized(&self, _: InitializedParams) {
self.client.log_message(MessageType::Info, "server initialized!");
self.client.log_message(MessageType::Info, "server initialized!").await;
}

async fn shutdown(&self) -> Result<()> {
Expand Down
143 changes: 73 additions & 70 deletions crates/server/src/service/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,85 +14,88 @@ pub(crate) mod tree {
pub(crate) async fn change(session: Arc<Session>, uri: Url) -> Fallible<()> {
if let Some(document) = session.get_document(&uri).await? {
let tree = document.tree.lock().await.clone();
let node = tree.root_node();
let mut diagnostics = vec![];
if node.has_error() {
// prepare a query to match tree-sitter ERROR nodes
let language = tree.language();
let source = "((ERROR) @error)"; // query the tree for ERROR nodes
let query = tree_sitter::Query::new(language, source).map_err(Error::TreeSitterQueryError)?;
let diagnostics = {
let mut diagnostics = vec![];
let node = tree.root_node();
if node.has_error() {
// prepare a query to match tree-sitter ERROR nodes
let language = tree.language();
let source = "((ERROR) @error)"; // query the tree for ERROR nodes
let query = tree_sitter::Query::new(language, source).map_err(Error::TreeSitterQueryError)?;

// prepare a query cursor
let mut query_cursor = tree_sitter::QueryCursor::new();
let text_callback = |node: tree_sitter::Node| &document.text[node.byte_range()];
let matches = query_cursor.matches(&query, node, text_callback);
// prepare a query cursor
let mut query_cursor = tree_sitter::QueryCursor::new();
let text_callback = |node: tree_sitter::Node| &document.text[node.byte_range()];
let matches = query_cursor.matches(&query, node, text_callback);

// iterate the query cursor and construct appropriate lsp diagnostics
for tree_sitter::QueryMatch { captures, .. } in matches {
'captures: for tree_sitter::QueryCapture { node, .. } in captures {
// create a cursor node starting from the capture node
let mut cursor = *node;
// iterate the query cursor and construct appropriate lsp diagnostics
for tree_sitter::QueryMatch { captures, .. } in matches {
'captures: for tree_sitter::QueryCapture { node, .. } in captures {
// create a cursor node starting from the capture node
let mut cursor = *node;

// traverse upward through the parent nodes
'cursor: while let Some(parent) = cursor.parent() {
cursor = parent;
// ignore further processing if the first non-ERROR
// parent node is a comment node; we do this in
// order to avoid syntax errors due to encoding
// issues (see "comments.wast" and issue #42)
if !cursor.is_error() {
match document.language {
Language::Wast
if [
*wast::kind::COMMENT_BLOCK_ANNOT,
*wast::kind::COMMENT_BLOCK,
*wast::kind::COMMENT_LINE_ANNOT,
*wast::kind::COMMENT_LINE,
]
.contains(&parent.kind_id()) =>
{
break 'captures;
// traverse upward through the parent nodes
'cursor: while let Some(parent) = cursor.parent() {
cursor = parent;
// ignore further processing if the first non-ERROR
// parent node is a comment node; we do this in
// order to avoid syntax errors due to encoding
// issues (see "comments.wast" and issue #42)
if !cursor.is_error() {
match document.language {
Language::Wast
if [
*wast::kind::COMMENT_BLOCK_ANNOT,
*wast::kind::COMMENT_BLOCK,
*wast::kind::COMMENT_LINE_ANNOT,
*wast::kind::COMMENT_LINE,
]
.contains(&parent.kind_id()) =>
{
break 'captures;
}
Language::Wat
if [
*wat::kind::COMMENT_BLOCK_ANNOT,
*wat::kind::COMMENT_BLOCK,
*wat::kind::COMMENT_LINE_ANNOT,
*wat::kind::COMMENT_LINE,
]
.contains(&parent.kind_id()) =>
{
break 'captures;
}
_ => {
break 'cursor;
},
}
Language::Wat
if [
*wat::kind::COMMENT_BLOCK_ANNOT,
*wat::kind::COMMENT_BLOCK,
*wat::kind::COMMENT_LINE_ANNOT,
*wat::kind::COMMENT_LINE,
]
.contains(&parent.kind_id()) =>
{
break 'captures;
}
_ => {
break 'cursor;
},
}
}
}

let start = node.start_position();
let end = node.end_position();
diagnostics.push({
let range = {
let start = Position::new(start.row as u64, start.column as u64);
let end = Position::new(end.row as u64, end.column as u64);
Range::new(start, end)
};
let severity = Some(DiagnosticSeverity::Error);
let code = None;
let source = Some(String::from("wasm-lsp"));
let message = String::from("syntax error");
let related_information = None;
let tags = None;
Diagnostic::new(range, severity, code, source, message, related_information, tags)
});
let start = node.start_position();
let end = node.end_position();
diagnostics.push({
let range = {
let start = Position::new(start.row as u64, start.column as u64);
let end = Position::new(end.row as u64, end.column as u64);
Range::new(start, end)
};
let severity = Some(DiagnosticSeverity::Error);
let code = None;
let source = Some(String::from("wasm-lsp"));
let message = String::from("syntax error");
let related_information = None;
let tags = None;
Diagnostic::new(range, severity, code, source, message, related_information, tags)
});
}
}
}
}
// NOTE: else let elaborator handle
// NOTE: else let elaborator handle
diagnostics
};
let version = None;
session.client.publish_diagnostics(uri.clone(), diagnostics, version);
session.client.publish_diagnostics(uri, diagnostics, version).await;
}
Ok(())
}
Expand All @@ -103,7 +106,7 @@ pub(crate) mod tree {
// FIXME: handle this properly
let diagnostics = vec![];
let version = None;
session.client.publish_diagnostics(uri, diagnostics, version);
session.client.publish_diagnostics(uri, diagnostics, version).await;
Ok(())
}

Expand Down