Skip to content

Commit

Permalink
chore: bump lsp-types from 0.95.0 to 0.97.0
Browse files Browse the repository at this point in the history
Bumps [lsp-types](https://github.com/gluon-lang/lsp-types) from 0.95.0 to 0.97.0.
- [Changelog](https://github.com/gluon-lang/lsp-types/blob/master/CHANGELOG.md)
- [Commits](gluon-lang/lsp-types@v0.95.0...v0.97.0)

---
updated-dependencies:
- dependency-name: lsp-types
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
  • Loading branch information
dependabot[bot] authored and polarmutex committed Oct 27, 2024
1 parent 5d2767e commit e0aff37
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 73 deletions.
49 changes: 29 additions & 20 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ crossbeam-channel = "0.5.13"
dashmap = "6.1"
glob = "0.3"
lsp-server = "0.7.7"
lsp-types = "0.95.0"
lsp-types = "0.97.0"
regex = "1"
ropey = "1.6"
thiserror = "1.0"
Expand All @@ -33,6 +33,7 @@ tree-sitter = "0.22"
tree-sitter-beancount = "2"
#tree-sitter-beancount = {git = "https://github.com/polarmutex/tree-sitter-beancount.git", branch="devel"}
threadpool = "1.8.1"
url = "2"

[dependencies.tracing-subscriber]
version = "0.3.18"
Expand Down
31 changes: 21 additions & 10 deletions crates/lsp/src/forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ use crate::beancount_data::BeancountData;
use crate::server::LspServerStateSnapshot;
use crate::server::ProgressMsg;
use crate::server::Task;
use crate::utils::ToFilePath;
use crossbeam_channel::Sender;
use glob::glob;
use std::collections::linked_list::LinkedList;
use std::fs;
use std::path;
use std::path::PathBuf;
use std::str::FromStr;
use tracing::error;

// Issus to look at if running into issues with this
// https://github.com/silvanshade/lspower/issues/8
pub(crate) fn parse_initial_forest(
snapshot: LspServerStateSnapshot,
root_url: lsp_types::Url,
root_url: PathBuf,
sender: Sender<Task>,
) -> anyhow::Result<bool, anyhow::Error> {
let mut seen_files = LinkedList::new();
Expand Down Expand Up @@ -43,17 +46,15 @@ pub(crate) fn parse_initial_forest(

while iter.peek().is_some() {
let file = iter.next().unwrap();
tracing::info!("processing {:#?}", file);
//session
// .client
// .log_message(lsp::MessageType::INFO, format!("parsing {}", file.as_ref()))
// .await;

let file_path = file.to_file_path().ok().unwrap();

processed += 1;
tracing::info!("processing {}", file.to_string());

let text = fs::read_to_string(file_path.clone())?;
let text = fs::read_to_string(file.clone())?;
let bytes = text.as_bytes();

let mut parser = tree_sitter::Parser::new();
Expand Down Expand Up @@ -94,23 +95,33 @@ pub(crate) fn parse_initial_forest(

let path = if path.is_absolute() {
path.to_path_buf()
} else if file_path.is_absolute() {
file_path.parent().unwrap().join(path)
} else if file.is_absolute() {
file.parent().unwrap().join(path)
} else {
path.to_path_buf()
};
let path_url = lsp_types::Url::from_file_path(path).unwrap();
let path_url = lsp_types::Uri::from_str(
format!("file://{}", path.to_str().unwrap()).as_str(),
)
.unwrap();

Some(path_url)
});

// This could get in an infinite loop if there is a loop wtth the include files
// TODO see if I can prevent this
for include_url in include_filenames {
for entry in glob(include_url.path()).expect("Failed to read glob") {
for entry in glob(include_url.to_file_path().unwrap().to_str().unwrap())
.expect("Failed to read glob")
{
match entry {
Ok(path) => {
let url = lsp_types::Url::from_file_path(path).unwrap();
let url = lsp_types::Uri::from_str(
format!("file://{}", path.to_str().unwrap()).as_str(),
)
.unwrap()
.to_file_path()
.unwrap();
if !snapshot.forest.contains_key(&url) {
total += 1;
new_to_processs.push_back(url);
Expand Down
19 changes: 12 additions & 7 deletions crates/lsp/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ pub mod text_document {
use crate::server::Task;
use crate::to_json;
use crate::treesitter_utils::lsp_textdocchange_to_ts_inputedit;
use crate::utils::ToFilePath;
use anyhow::Result;
use crossbeam_channel::Sender;
use lsp_types::notification::Notification;
use std::path::PathBuf;
use std::str::FromStr;
use tracing::debug;

/// handler for `textDocument/didOpen`.
Expand All @@ -22,11 +24,11 @@ pub mod text_document {
params: lsp_types::DidOpenTextDocumentParams,
) -> Result<()> {
debug!("handlers::did_open");
let uri = params.text_document.uri.clone();
let uri = params.text_document.uri.to_file_path().unwrap();

let document = Document::open(params.clone());
//let tree = document.tree.clone();
tracing::debug!("handlers::did_open - adding {}", uri);
tracing::debug!("handlers::did_open - adding {:#?}", &uri);
state.open_docs.insert(uri.clone(), document);

state.parsers.entry(uri.clone()).or_insert_with(|| {
Expand Down Expand Up @@ -79,7 +81,7 @@ pub mod text_document {
params: lsp_types::DidCloseTextDocumentParams,
) -> Result<()> {
tracing::debug!("handlers::did_close");
let uri = params.text_document.uri;
let uri = params.text_document.uri.to_file_path().unwrap();
state.open_docs.remove(&uri);
// let version = Default::default();
Ok(())
Expand All @@ -91,8 +93,8 @@ pub mod text_document {
params: lsp_types::DidChangeTextDocumentParams,
) -> Result<()> {
tracing::debug!("handlers::did_change");
let uri = &params.text_document.uri;
tracing::debug!("handlers::did_change - requesting {}", uri);
let uri = &params.text_document.uri.to_file_path().unwrap();
tracing::debug!("handlers::did_change - requesting {:#?}", uri);
let doc = state.open_docs.get_mut(uri).unwrap();

tracing::debug!("handlers::did_change - convert edits");
Expand Down Expand Up @@ -202,7 +204,7 @@ pub mod text_document {
fn handle_diagnostics(
snapshot: LspServerStateSnapshot,
sender: Sender<Task>,
uri: lsp_types::Url,
uri: lsp_types::Uri,
) -> Result<()> {
tracing::debug!("handlers::check_beancount");
let bean_check_cmd = &PathBuf::from("bean-check");
Expand Down Expand Up @@ -234,7 +236,10 @@ pub mod text_document {
.send(Task::Notify(lsp_server::Notification {
method: lsp_types::notification::PublishDiagnostics::METHOD.to_owned(),
params: to_json(lsp_types::PublishDiagnosticsParams {
uri: file.clone(),
uri: lsp_types::Uri::from_str(
format!("file://{}", file.to_str().unwrap()).as_str(),
)
.unwrap(),
diagnostics,
version: None,
})
Expand Down
2 changes: 2 additions & 0 deletions crates/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ pub mod providers;
pub mod server;
//pub mod session;
mod treesitter_utils;
mod utils;

use crate::config::Config;
use crate::server::LspServerState;
use anyhow::Result;
use lsp_server::Connection;
use lsp_types::InitializeParams;
use serde::{de::DeserializeOwned, Serialize};
use utils::ToFilePath;

pub fn run_server() -> Result<()> {
tracing::info!("beancount-language-server started");
Expand Down
Loading

0 comments on commit e0aff37

Please sign in to comment.