From 6781cd02cd272994dd9c1eaa201cb79dfcbe9b7b Mon Sep 17 00:00:00 2001 From: techwritescode <10032418+techwritescode@users.noreply.github.com> Date: Sun, 10 Aug 2025 11:36:47 -0500 Subject: [PATCH 1/2] Fix inconsistent paths --- lsp/src/asm_server.rs | 2 +- lsp/src/data/convert_uri.rs | 13 ++++++++++-- lsp/src/index_engine.rs | 2 +- lsp/src/state.rs | 41 +++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/lsp/src/asm_server.rs b/lsp/src/asm_server.rs index 306aa3d..f543385 100644 --- a/lsp/src/asm_server.rs +++ b/lsp/src/asm_server.rs @@ -171,7 +171,7 @@ impl LanguageServer for Asm { let mut state = self.state.lock().await; if let Some(workspace_folders) = params.workspace_folders { if !workspace_folders.is_empty() { - state.workspace_folder = Some(workspace_folders.first().unwrap().clone().uri) + state.set_workspace_folder(workspace_folders.first().unwrap().clone().uri); } } diff --git a/lsp/src/data/convert_uri.rs b/lsp/src/data/convert_uri.rs index 71bfe71..c34d0b3 100644 --- a/lsp/src/data/convert_uri.rs +++ b/lsp/src/data/convert_uri.rs @@ -1,7 +1,9 @@ +use std::fmt::format; use std::str::FromStr; use anyhow::anyhow; use tower_lsp_server::lsp_types::Uri; use urlencoding::encode; +use crate::state::{URI_MODE, UriMode}; #[cfg(target_os = "windows")] pub fn convert_uri(uri: Uri) -> anyhow::Result { @@ -12,8 +14,15 @@ pub fn convert_uri(uri: Uri) -> anyhow::Result { let drive_letter = segments[0].chars().next().unwrap(); - let drive = format!("{}:", drive_letter.to_ascii_lowercase()); - segments[0] = encode(&drive).to_string(); + segments[0] = match *URI_MODE.lock().unwrap() { + UriMode::VSCode => { + let drive = format!("{}:", drive_letter.to_ascii_lowercase()); + encode(&drive).to_string() + } + UriMode::Helix => { + format!("{}:", drive_letter.to_ascii_uppercase()) + } + }; let path = format!("file:///{}", segments.join("/")); Uri::from_str(&path).map_err(|e| anyhow!(e)) diff --git a/lsp/src/index_engine.rs b/lsp/src/index_engine.rs index ec4d0f5..519bf22 100644 --- a/lsp/src/index_engine.rs +++ b/lsp/src/index_engine.rs @@ -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 { diff --git a/lsp/src/state.rs b/lsp/src/state.rs index 0f68d5e..bacb44c 100644 --- a/lsp/src/state.rs +++ b/lsp/src/state.rs @@ -1,12 +1,20 @@ use crate::{data::files::Files, data::units::Units}; use codespan::FileId; use std::str::FromStr; +use std::sync::Mutex; +use lazy_static::lazy_static; use tower_lsp_server::Client; use tower_lsp_server::lsp_types::{ ClientCapabilities, Diagnostic, TextDocumentContentChangeEvent, Uri, VersionedTextDocumentIdentifier, }; +#[derive(Debug)] +pub enum UriMode { + VSCode, + Helix, +} + pub struct State { pub files: Files, pub workspace_folder: Option, @@ -15,6 +23,10 @@ pub struct State { pub units: Units, } +lazy_static! { + pub static ref URI_MODE: Mutex = Mutex::new(UriMode::VSCode); +} + impl State { pub fn new(client: Client) -> Self { Self { @@ -67,4 +79,33 @@ impl State { ) .await; } + + pub fn set_workspace_folder(&mut self, workspace_folder: Uri) { + self.workspace_folder = Some(workspace_folder); + self.detect_uri_mode(); + } + + #[cfg(target_os = "windows")] + fn detect_uri_mode(&mut self) { + let root = self.workspace_folder.clone().unwrap(); + let segments = root.path().segments(); + let mut segments = segments + .map(|segments| segments.to_string()) + .collect::>(); + + let drive_letter = segments[0].to_owned(); + + if matches!(drive_letter.chars().nth(1), Some(':')) { + // Helix mode: drive letters are C: + *URI_MODE.lock().unwrap() = UriMode::Helix; + } else { + // VS Code mode: drive letters are c%3A + *URI_MODE.lock().unwrap() = UriMode::VSCode; + } + } + + #[cfg(not(target_os = "windows"))] + fn detect_uri_mode(&mut self) { + self.uri_mode = UriMode::VSCode; // Should work for helix on mac & linux + } } From 4c418ce1b6aafa662f5c4af421826a4481921e30 Mon Sep 17 00:00:00 2001 From: techwritescode <10032418+techwritescode@users.noreply.github.com> Date: Sun, 10 Aug 2025 11:40:06 -0500 Subject: [PATCH 2/2] Fix non-windows --- lsp/src/state.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lsp/src/state.rs b/lsp/src/state.rs index bacb44c..936490c 100644 --- a/lsp/src/state.rs +++ b/lsp/src/state.rs @@ -106,6 +106,7 @@ impl State { #[cfg(not(target_os = "windows"))] fn detect_uri_mode(&mut self) { - self.uri_mode = UriMode::VSCode; // Should work for helix on mac & linux + // Should work for helix on mac & linux as well + // URI_MODE defaults to VS Code, so no changes needed } }