mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
fix: path handling bug
This commit is contained in:
parent
74d304a1b7
commit
cfc2214bfb
8 changed files with 26 additions and 21 deletions
|
@ -31,6 +31,7 @@ use lsp_types::{
|
|||
MarkupContent, MarkupKind, Position, Range, TextEdit,
|
||||
};
|
||||
|
||||
use crate::_log;
|
||||
use crate::server::{ELSResult, Flags, RedirectableStdout, Server};
|
||||
use crate::util::{self, loc_to_pos, NormalizedUrl};
|
||||
|
||||
|
@ -494,7 +495,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
&mut self,
|
||||
params: CompletionParams,
|
||||
) -> ELSResult<Option<CompletionResponse>> {
|
||||
self.send_log(format!("completion requested: {params:?}"))?;
|
||||
_log!(self, "completion requested: {params:?}");
|
||||
let uri = NormalizedUrl::new(params.text_document_position.text_document.uri);
|
||||
let path = util::uri_to_path(&uri);
|
||||
let mut pos = params.text_document_position.position;
|
||||
|
@ -587,6 +588,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
_ => None,
|
||||
});
|
||||
let Some(mod_ctx) = self.get_mod_ctx(&uri) else {
|
||||
_log!(self, "module context not found: {uri}");
|
||||
return Ok(None);
|
||||
};
|
||||
for (name, vi) in contexts.into_iter().flat_map(|ctx| ctx.local_dir()) {
|
||||
|
@ -637,7 +639,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
}
|
||||
result.extend(self.neighbor_completion(&uri, arg_pt, &mut already_appeared));
|
||||
}
|
||||
self.send_log(format!("completion items: {}", result.len()))?;
|
||||
_log!(self, "completion items: {}", result.len());
|
||||
Ok(Some(CompletionResponse::Array(result)))
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
} else if let Some(visitor) = self.get_visitor(uri) {
|
||||
Ok(visitor.get_info(token))
|
||||
} else {
|
||||
self.send_log("not found")?;
|
||||
self.send_log("definition not found")?;
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,11 +185,11 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
return Ok(());
|
||||
}
|
||||
let Some(old) = self.get_ast(&uri) else {
|
||||
crate::_log!(self, "not found");
|
||||
crate::_log!(self, "AST not found: {uri}");
|
||||
return Ok(());
|
||||
};
|
||||
let Ok(new) = self.build_ast(&uri) else {
|
||||
crate::_log!(self, "not found");
|
||||
crate::_log!(self, "AST not found: {uri}");
|
||||
return Ok(());
|
||||
};
|
||||
let ast_diff = ASTDiff::diff(old, &new);
|
||||
|
|
|
@ -146,7 +146,7 @@ impl FileCache {
|
|||
.files
|
||||
.borrow_mut()
|
||||
.get(uri)
|
||||
.ok_or("not found")?
|
||||
.ok_or("file entry not found")?
|
||||
.code
|
||||
.clone())
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ impl FileCache {
|
|||
) -> ELSResult<Option<String>> {
|
||||
self.load_once(uri)?;
|
||||
let ent = self.files.borrow_mut();
|
||||
let file = ent.get(uri).ok_or("not found")?;
|
||||
let file = ent.get(uri).ok_or("file entry not found")?;
|
||||
let mut code = String::new();
|
||||
for (i, line) in file.code.lines().enumerate() {
|
||||
if i >= range.start.line as usize && i <= range.end.line as usize {
|
||||
|
|
|
@ -755,7 +755,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
Some(MappedRwLockReadGuard::map(ent, |ent| &ent.module))
|
||||
}
|
||||
|
||||
pub(crate) fn raw_get_mod_ctx(&self, uri: &NormalizedUrl) -> Option<&ModuleContext> {
|
||||
pub(crate) fn get_raw_mod_ctx(&self, uri: &NormalizedUrl) -> Option<&ModuleContext> {
|
||||
let path = uri.to_file_path().ok()?;
|
||||
self.shared.raw_ref_ctx(&path)
|
||||
}
|
||||
|
@ -789,7 +789,10 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
|
||||
pub(crate) fn get_visitor(&self, uri: &NormalizedUrl) -> Option<HIRVisitor> {
|
||||
let path = uri.to_file_path().ok()?;
|
||||
let ent = self.shared.get_module(&path)?;
|
||||
let Some(ent) = self.shared.get_module(&path) else {
|
||||
_log!(self, "module not found: {uri}");
|
||||
return None;
|
||||
};
|
||||
ent.hir.as_ref()?;
|
||||
let hir = MappedRwLockReadGuard::map(ent, |ent| ent.hir.as_ref().unwrap());
|
||||
Some(HIRVisitor::new(hir, &self.file_cache, uri.clone()))
|
||||
|
@ -810,7 +813,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
|
||||
pub(crate) fn get_local_ctx(&self, uri: &NormalizedUrl, pos: Position) -> Vec<&Context> {
|
||||
let mut ctxs = vec![];
|
||||
if let Some(mod_ctx) = self.raw_get_mod_ctx(uri) {
|
||||
if let Some(mod_ctx) = self.get_raw_mod_ctx(uri) {
|
||||
if let Some(visitor) = self.get_visitor(uri) {
|
||||
// FIXME:
|
||||
let mut ns = visitor.get_namespace(pos);
|
||||
|
@ -826,7 +829,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
}
|
||||
ctxs.push(&mod_ctx.context);
|
||||
}
|
||||
let builtin_ctx = self.get_builtin_module();
|
||||
let builtin_ctx = self.get_raw_builtin_module();
|
||||
ctxs.extend(builtin_ctx);
|
||||
ctxs
|
||||
}
|
||||
|
@ -859,7 +862,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
continue;
|
||||
};
|
||||
let uri = NormalizedUrl::from_file_path(neighbor.path()).unwrap();
|
||||
if let Some(mod_ctx) = self.raw_get_mod_ctx(&uri) {
|
||||
if let Some(mod_ctx) = self.get_raw_mod_ctx(&uri) {
|
||||
ctxs.push(&mod_ctx.context);
|
||||
}
|
||||
}
|
||||
|
@ -872,7 +875,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
uri: &NormalizedUrl,
|
||||
attr_marker_pos: Position,
|
||||
) -> ELSResult<(Option<Type>, Vec<&Context>)> {
|
||||
let Some(module) = self.raw_get_mod_ctx(uri) else {
|
||||
let Some(module) = self.get_raw_mod_ctx(uri) else {
|
||||
return Ok((None, vec![]));
|
||||
};
|
||||
let maybe_token = self.file_cache.get_receiver(uri, attr_marker_pos);
|
||||
|
@ -909,7 +912,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_builtin_module(&self) -> Option<&Context> {
|
||||
pub(crate) fn get_raw_builtin_module(&self) -> Option<&Context> {
|
||||
self.shared.raw_ref_builtins_ctx().map(|mc| &mc.context)
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ COMMAND
|
|||
compile compile
|
||||
transpile transpile
|
||||
run|exec execute (default mode)
|
||||
server execute language server",
|
||||
server start Erg language server",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -2968,7 +2968,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
|||
let mut builder = GenericHIRBuilder::<A>::new_submodule(mod_ctx, &mod_name);
|
||||
builder.lowerer.module.context.cfg.input = inline.input.clone();
|
||||
builder.cfg_mut().input = inline.input.clone();
|
||||
let mode = if path.to_string_lossy().ends_with("d.er") {
|
||||
let mode = if path.to_string_lossy().ends_with(".d.er") {
|
||||
"declare"
|
||||
} else {
|
||||
"exec"
|
||||
|
@ -2985,7 +2985,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
|||
}
|
||||
};
|
||||
let ctx = builder.pop_mod_ctx().unwrap();
|
||||
let cache = if path.to_string_lossy().ends_with("d.er") {
|
||||
let cache = if path.to_string_lossy().ends_with(".d.er") {
|
||||
&self.module.context.shared().py_mod_cache
|
||||
} else {
|
||||
&self.module.context.shared().mod_cache
|
||||
|
|
|
@ -97,7 +97,7 @@ impl SharedCompilerResource {
|
|||
}
|
||||
|
||||
pub fn insert_module(&self, path: NormalizedPathBuf, entry: ModuleEntry) {
|
||||
if path.to_string_lossy().ends_with("d.er") {
|
||||
if path.to_string_lossy().ends_with(".d.er") {
|
||||
self.py_mod_cache.insert(path, entry);
|
||||
} else {
|
||||
self.mod_cache.insert(path, entry);
|
||||
|
@ -105,7 +105,7 @@ impl SharedCompilerResource {
|
|||
}
|
||||
|
||||
pub fn remove_module(&self, path: &std::path::Path) -> Option<ModuleEntry> {
|
||||
if path.to_string_lossy().ends_with("d.er") {
|
||||
if path.to_string_lossy().ends_with(".d.er") {
|
||||
self.py_mod_cache.remove(path)
|
||||
} else {
|
||||
self.mod_cache.remove(path)
|
||||
|
@ -113,7 +113,7 @@ impl SharedCompilerResource {
|
|||
}
|
||||
|
||||
pub fn get_module(&self, path: &std::path::Path) -> Option<MappedRwLockReadGuard<ModuleEntry>> {
|
||||
if path.to_string_lossy().ends_with("d.er") {
|
||||
if path.to_string_lossy().ends_with(".d.er") {
|
||||
self.py_mod_cache.get(path)
|
||||
} else {
|
||||
self.mod_cache.get(path)
|
||||
|
@ -121,7 +121,7 @@ impl SharedCompilerResource {
|
|||
}
|
||||
|
||||
pub fn raw_ref_ctx(&self, path: &std::path::Path) -> Option<&ModuleContext> {
|
||||
if path.to_string_lossy().ends_with("d.er") {
|
||||
if path.to_string_lossy().ends_with(".d.er") {
|
||||
self.py_mod_cache.raw_ref_ctx(path)
|
||||
} else {
|
||||
self.mod_cache.raw_ref_ctx(path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue