mirror of
https://github.com/ribru17/ts_query_ls.git
synced 2025-12-23 05:36:52 +00:00
fix: enable non-error logs (#3)
This commit is contained in:
parent
42bf128a30
commit
f8ec7a3aae
3 changed files with 109 additions and 67 deletions
91
Cargo.lock
generated
91
Cargo.lock
generated
|
|
@ -868,6 +868,16 @@ dependencies = [
|
|||
"adler2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||
dependencies = [
|
||||
"overload",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.36.5"
|
||||
|
|
@ -886,6 +896,12 @@ version = "1.20.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.10"
|
||||
|
|
@ -1129,6 +1145,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
|
|
@ -1240,6 +1265,16 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.7.6"
|
||||
|
|
@ -1374,6 +1409,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||
dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
|
||||
dependencies = [
|
||||
"nu-ansi-term",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1415,6 +1476,7 @@ dependencies = [
|
|||
"env_logger",
|
||||
"lazy_static",
|
||||
"libloading",
|
||||
"log",
|
||||
"regex",
|
||||
"ropey",
|
||||
"serde",
|
||||
|
|
@ -1422,6 +1484,7 @@ dependencies = [
|
|||
"streaming-iterator",
|
||||
"tokio",
|
||||
"tower-lsp",
|
||||
"tracing-subscriber",
|
||||
"tree-sitter",
|
||||
"tree-sitter-query",
|
||||
]
|
||||
|
|
@ -1468,6 +1531,12 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
|
|
@ -1705,6 +1774,22 @@ dependencies = [
|
|||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.9"
|
||||
|
|
@ -1714,6 +1799,12 @@ dependencies = [
|
|||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ dissimilar = "1.0.9"
|
|||
env_logger = "0.11.5"
|
||||
lazy_static = "1.5.0"
|
||||
libloading = "0.8.5"
|
||||
log = "0.4.22"
|
||||
regex = "1.11.0"
|
||||
ropey = "1.6.1"
|
||||
serde = "1.0.210"
|
||||
|
|
@ -17,6 +18,7 @@ serde_json = "1.0.132"
|
|||
streaming-iterator = "0.1.9"
|
||||
tokio = { version = "1.40.0", features = ["rt-multi-thread", "macros", "io-std"] }
|
||||
tower-lsp = "0.20.0"
|
||||
tracing-subscriber = "0.3.18"
|
||||
tree-sitter = { version = "0.24.4", features = ["std", "wasm"] }
|
||||
tree-sitter-query = { git = "https://github.com/tree-sitter-grammars/tree-sitter-query", rev = "d0d9126a9b80a0bb609acdf960d3f1613fc319db", version = "0.4.0" }
|
||||
|
||||
|
|
|
|||
83
src/main.rs
83
src/main.rs
|
|
@ -1,4 +1,5 @@
|
|||
use lazy_static::lazy_static;
|
||||
use log::{error, info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
|
|
@ -310,21 +311,11 @@ mod util;
|
|||
#[tower_lsp::async_trait]
|
||||
impl LanguageServer for Backend {
|
||||
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::LOG,
|
||||
format!("ts_query_ls initialize: {:?}", params),
|
||||
)
|
||||
.await;
|
||||
info!("ts_query_ls initialize: {params:?}");
|
||||
if let Some(root_uri) = params.root_uri {
|
||||
let root = PathBuf::from(root_uri.path());
|
||||
if set_current_dir(&root).is_err() {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::ERROR,
|
||||
format!("Failed to set root directory to {:?}", root),
|
||||
)
|
||||
.await;
|
||||
error!("Failed to set root directory to {:?}", root);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -352,12 +343,7 @@ impl LanguageServer for Backend {
|
|||
if let Ok(options) = serde_json::from_value::<Options>(params.settings) {
|
||||
options
|
||||
} else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
"Unable to parse configuration settings!",
|
||||
)
|
||||
.await;
|
||||
warn!("Unable to parse configuration settings!",);
|
||||
return;
|
||||
};
|
||||
let mut options = self.options.write().unwrap();
|
||||
|
|
@ -377,12 +363,7 @@ impl LanguageServer for Backend {
|
|||
&self,
|
||||
params: GotoDefinitionParams,
|
||||
) -> Result<Option<GotoDefinitionResponse>> {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::LOG,
|
||||
format!("ts_query_ls goto_definition: {:?}", params),
|
||||
)
|
||||
.await;
|
||||
info!("ts_query_ls goto_definition: {params:?}", );
|
||||
let uri = params.text_document_position_params.text_document.uri;
|
||||
let pos = Position {
|
||||
line: params.text_document_position_params.position.line,
|
||||
|
|
@ -397,12 +378,7 @@ impl LanguageServer for Backend {
|
|||
|
||||
async fn did_open(&self, params: DidOpenTextDocumentParams) {
|
||||
let uri = ¶ms.text_document.uri;
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::LOG,
|
||||
format!("ts_query_ls did_open: {:?}", params),
|
||||
)
|
||||
.await;
|
||||
info!("ts_query_ls did_ops: {params:?}");
|
||||
let contents = params.text_document.text;
|
||||
let rope = Rope::from_str(&contents);
|
||||
let mut parser = Parser::new();
|
||||
|
|
@ -589,21 +565,11 @@ impl LanguageServer for Backend {
|
|||
let uri = ¶ms.text_document_position.text_document.uri;
|
||||
|
||||
let Some(tree) = self.ast_map.get(uri) else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
format!("No AST built for URI: {:?}", *uri),
|
||||
)
|
||||
.await;
|
||||
warn!("No AST built for URI: {uri:?}");
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(rope) = self.document_map.get(uri) else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
format!("No document built for URI: {:?}", *uri),
|
||||
)
|
||||
.await;
|
||||
warn!("No document built for URI: {uri:?}");
|
||||
return Ok(None);
|
||||
};
|
||||
let cur_pos = lsp_position_to_ts_point(params.text_document_position.position, &rope);
|
||||
|
|
@ -638,21 +604,11 @@ impl LanguageServer for Backend {
|
|||
async fn rename(&self, params: RenameParams) -> Result<Option<WorkspaceEdit>> {
|
||||
let uri = params.text_document_position.text_document.uri;
|
||||
let Some(tree) = self.ast_map.get(&uri) else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
format!("No AST built for URI: {:?}", uri),
|
||||
)
|
||||
.await;
|
||||
warn!("No AST built for URI: {uri:?}");
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(rope) = self.document_map.get(&uri) else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
format!("No document built for URI: {:?}", uri),
|
||||
)
|
||||
.await;
|
||||
warn!("No document built for URI: {uri:?}");
|
||||
return Ok(None);
|
||||
};
|
||||
let current_node = match get_current_capture_node(
|
||||
|
|
@ -727,21 +683,11 @@ impl LanguageServer for Backend {
|
|||
let uri = ¶ms.text_document_position.text_document.uri;
|
||||
|
||||
let Some(tree) = self.ast_map.get(uri) else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
format!("No AST built for URI: {:?}", *uri),
|
||||
)
|
||||
.await;
|
||||
warn!("No AST built for URI: {uri:?}");
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(rope) = self.document_map.get(uri) else {
|
||||
self.client
|
||||
.log_message(
|
||||
MessageType::WARNING,
|
||||
format!("No document built for URI: {:?}", *uri),
|
||||
)
|
||||
.await;
|
||||
warn!("No document built for URI: {uri:?}");
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
|
|
@ -900,7 +846,10 @@ impl LanguageServer for Backend {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env_logger::init();
|
||||
tracing_subscriber::fmt()
|
||||
.with_writer(std::io::stderr)
|
||||
.with_ansi(false)
|
||||
.init();
|
||||
|
||||
let stdin = tokio::io::stdin();
|
||||
let stdout = tokio::io::stdout();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue