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
2 changes: 1 addition & 1 deletion lsp/src/asm_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 11 additions & 2 deletions lsp/src/data/convert_uri.rs
Original file line number Diff line number Diff line change
@@ -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<Uri> {
Expand All @@ -12,8 +14,15 @@ pub fn convert_uri(uri: Uri) -> anyhow::Result<Uri> {

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())
}
Comment on lines +18 to +24
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So VSCode does NOT allow C: and helix does NOT allow c:? do we know about neovim and zed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure about those two, but they should fall into one of the two categories.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve and we'll see. Neither of us daily drive those so shouldn't be a problem yet

};

let path = format!("file:///{}", segments.join("/"));
Uri::from_str(&path).map_err(|e| anyhow!(e))
Expand Down
2 changes: 1 addition & 1 deletion lsp/src/index_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 42 additions & 0 deletions lsp/src/state.rs
Original file line number Diff line number Diff line change
@@ -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<Uri>,
Expand All @@ -15,6 +23,10 @@ pub struct State {
pub units: Units,
}

lazy_static! {
pub static ref URI_MODE: Mutex<UriMode> = Mutex::new(UriMode::VSCode);
}

impl State {
pub fn new(client: Client) -> Self {
Self {
Expand Down Expand Up @@ -67,4 +79,34 @@ 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::<Vec<_>>();

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) {
// Should work for helix on mac & linux as well
// URI_MODE defaults to VS Code, so no changes needed
}
}
Loading