lsp import

This commit is contained in:
agra
2026-02-24 20:05:24 +02:00
parent 06d10541da
commit bfc784734c
4 changed files with 40 additions and 27 deletions

View File

@@ -129,6 +129,7 @@ pub const Server = struct {
if (!std.mem.startsWith(u8, root_uri, prefix)) break :chdir;
const root_path = root_uri[prefix.len..];
self.root_path = self.allocator.dupe(u8, root_path) catch break :chdir;
self.documents.root_path = self.root_path;
const path_z = self.allocator.dupeZ(u8, root_path) catch break :chdir;
_ = std.c.chdir(path_z.ptr);
}
@@ -249,13 +250,11 @@ pub const Server = struct {
// 4. #import "path" string → open the file (or directory)
if (findImportPathAtOffset(doc.source, offset)) |import_path| {
const base_dir = sx.imports.dirName(file_path);
const resolved = if (std.mem.eql(u8, base_dir, "."))
import_path
else
try std.fmt.allocPrint(self.allocator, "{s}/{s}", .{ base_dir, import_path });
const rp: ?[]const u8 = if (self.root_path.len > 0) self.root_path else null;
const resolved = try sx.imports.resolveImportPath(self.allocator, self.io, base_dir, import_path, rp);
// For directory imports, try to read as file first
if (std.Io.Dir.readFileAlloc(.cwd(), self.io, resolved, self.allocator, .limited(1))) |_| {
if (std.Io.Dir.readFileAlloc(.cwd(), self.io, resolved, self.allocator, .limited(10 * 1024 * 1024))) |_| {
// It's a file — navigate to it
const target_uri = try std.fmt.allocPrint(self.allocator, "file://{s}", .{resolved});
const range = lsp.Range{