Skip to content
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ lazy_static = "1.5.0"
walkdir = "2.5.0"
uuid = { version = "1.17.0", features = ["v4"] }
url = "2.5.4"
urlencoding = "2.1.3"
path-clean = "1.0.1"
20 changes: 11 additions & 9 deletions lsp/src/asm_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ use tower_lsp_server::lsp_types::{
WorkspaceServerCapabilities,
};
use tower_lsp_server::{
Client, LanguageServer,
jsonrpc::Result,
lsp_types::{
jsonrpc::Result, lsp_types::{
DidChangeTextDocumentParams, DidOpenTextDocumentParams, GotoDefinitionParams,
GotoDefinitionResponse, Hover, HoverParams, InitializeParams, InitializeResult,
MarkedString, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind, Uri,
},
Client,
LanguageServer,
};
use crate::data::convert_uri::convert_uri;

#[allow(dead_code)]
pub struct Asm {
Expand Down Expand Up @@ -235,13 +236,11 @@ impl LanguageServer for Asm {
.expect("Failed to read config");
}

tokio::spawn(IndexEngine::crawl_fs(
IndexEngine::crawl_fs(
self.index_engine.clone(),
workspace_folder,
self.client.clone(),
))
.await
.unwrap();
).await;
}
}

Expand All @@ -251,7 +250,10 @@ impl LanguageServer for Asm {

async fn did_open(&self, params: DidOpenTextDocumentParams) {
let mut state = self.state.lock().await;
let id = state.get_or_insert_source(params.text_document.uri, params.text_document.text);
let id = state.get_or_insert_source(
convert_uri(params.text_document.uri).unwrap(),
params.text_document.text,
);
drop(state);

self.index(id).await;
Expand Down Expand Up @@ -594,4 +596,4 @@ fn scope_to_symbol(scope: &Scope, file: &CacheFile) -> Option<DocumentSymbol> {
} else {
None
}
}
}
25 changes: 25 additions & 0 deletions lsp/src/data/convert_uri.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::str::FromStr;
use anyhow::anyhow;
use tower_lsp_server::lsp_types::Uri;
use urlencoding::encode;

#[cfg(target_os = "windows")]
pub fn convert_uri(uri: Uri) -> anyhow::Result<Uri> {
let segments = uri.path().segments();
let mut segments = segments
.map(|segments| segments.to_string())
.collect::<Vec<_>>();

let drive_letter = segments[0].chars().next().unwrap();

let drive = format!("{}:", drive_letter.to_ascii_lowercase());
segments[0] = encode(&drive).to_string();

let path = format!("file:///{}", segments.join("/"));
Uri::from_str(&path).map_err(|e| anyhow!(e))
}

#[cfg(not(target_os = "windows"))]
pub fn convert_uri(uri: Uri) -> anyhow::Result<Uri> {
Ok(uri)
}
27 changes: 14 additions & 13 deletions lsp/src/data/files.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use crate::analysis::scope_analyzer;
use crate::analysis::scope_analyzer::ScopeAnalyzer;
use crate::cache_file::{CacheFile, Include, ResolvedInclude};
use crate::data::convert_uri::convert_uri;
use crate::data::indexing_state::IndexingState;
use crate::data::path::diff_paths;
use crate::data::symbol::{Symbol, SymbolType};
use anyhow::anyhow;
use codespan::{File, FileId, Position};
use parser::{ParseError, Token, TokenizerError};
use path_clean::PathClean;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::path::Path;
use std::str::FromStr;
use tower_lsp_server::lsp_types::{Diagnostic, Range, Uri};
use url::Url;

pub enum IndexError {
TokenizerError(TokenizerError),
Expand Down Expand Up @@ -94,17 +97,22 @@ impl Files {
return Ok(None);
}

let parent = PathBuf::from_str(parent_uri.path().as_str())?
let parent = Url::from_str(parent_uri.as_str())?
.to_file_path()
.map_err(|_| anyhow!("Failed to create pathbuf"))?
.parent()
.ok_or_else(|| anyhow::anyhow!("parent folder not found"))?
.join(path)
.clean();
let parent = Uri::from_str(url::Url::from_file_path(parent).unwrap().as_ref())?;

let parent = convert_uri(Uri::from_str(Url::from_file_path(parent).unwrap().as_ref())?)?;

let id = self
.sources
.iter()
.find_map(|(uri, id)| if *uri == parent { Some(*id) } else { None });
.find_map(|(uri, id)| {
if uri.as_str() == parent.as_str() { Some(*id) } else { None }
});

Ok(Some(id.ok_or_else(|| anyhow::anyhow!("file not found"))?))
}
Expand Down Expand Up @@ -143,15 +151,8 @@ impl Files {
}

pub fn resolve_imports_for_file(&self, parent: FileId) -> HashSet<FileId> {
// eprintln!("Crawling {:?}", parent);
let mut all_files = HashSet::new();
for include in self.get(parent).resolved_includes.iter() {
// eprintln!("Including {:?}", include);
// eprintln!(
// "Including {:?} from {:?}",
// state.files.get_uri(include.file).as_str(),
// state.files.get_uri(parent).as_str()
// );
if !all_files.contains(&include.file) && include.file != parent {
all_files.extend(self.resolve_imports_for_file(include.file));
}
Expand Down Expand Up @@ -236,6 +237,6 @@ fn is_includes_same(includes: &[Include], resolved_includes: &[ResolvedInclude])
return false;
}
}

true
}
}
1 change: 1 addition & 0 deletions lsp/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod path;
pub mod symbol;
pub mod units;
pub mod files;
pub mod convert_uri;
2 changes: 1 addition & 1 deletion lsp/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Definition {
id: FileId,
position: Position,
) -> Result<Option<(Vec<Symbol>, Span)>, FileError> {
let file = &state.files.get(id);
let file = state.files.get(id);
let units = state.units.find_related(id);
if units.len() == 0 {
// TODO: Not included
Expand Down
12 changes: 4 additions & 8 deletions lsp/src/index_engine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::analysis::scope_analyzer::Scope;
use crate::data::convert_uri::convert_uri;
use crate::data::files::Files;
use crate::data::symbol::Symbol;
use crate::state::State;
Expand All @@ -9,12 +9,12 @@ use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::Mutex;
use tower_lsp_server::Client;
use tower_lsp_server::lsp_types::request::WorkDoneProgressCreate;
use tower_lsp_server::lsp_types::{
Diagnostic, InlayHintWorkspaceClientCapabilities, ProgressToken, Uri,
WorkDoneProgressCreateParams, WorkspaceClientCapabilities,
};
use tower_lsp_server::Client;
use uuid::Uuid;

pub struct IndexEngine {
Expand Down Expand Up @@ -73,9 +73,9 @@ impl IndexEngine {
((idx as f32) / (sources.len() as f32) * 100.0) as u32,
)
.await;
let uri = Uri::from_str(url::Url::from_file_path(file).unwrap().as_ref()).unwrap();
let uri = Uri::from_str(url::Url::from_file_path(file).unwrap().as_str()).unwrap();
let contents = std::fs::read_to_string(file).unwrap();
let id = state.get_or_insert_source(uri, contents);
let id = state.get_or_insert_source(convert_uri(uri).unwrap(), contents);
let file = state.files.index(id).await;
diagnostics.insert(id, file.diagnostics);
parsed_files.push(id);
Expand Down Expand Up @@ -113,7 +113,6 @@ impl IndexEngine {
}

for id in parsed_files.iter() {
// let diags = IndexEngine::invalidate(&mut state, *id).await;
state
.publish_diagnostics(
*id,
Expand All @@ -138,10 +137,7 @@ impl IndexEngine {

let file = state.files.get_mut(file);
if resolved_imports.iter().ne(&file.resolved_includes) {
// eprintln!("Changed {:#?}", file.resolved_includes);
file.resolved_includes = resolved_imports;
} else {
// eprintln!("No changes");
}

diagnostics
Expand Down
Loading