Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_lsp): handle untitled files #4327

Merged
merged 1 commit into from
Mar 27, 2023
Merged
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
13 changes: 9 additions & 4 deletions crates/rome_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::documents::Document;
use crate::extension_settings::ExtensionSettings;
use crate::extension_settings::CONFIGURATION_SECTION;
use crate::utils;
use anyhow::{anyhow, Result};
use anyhow::Result;
use futures::stream::futures_unordered::FuturesUnordered;
use futures::StreamExt;
use rome_analyze::RuleCategories;
Expand Down Expand Up @@ -240,9 +240,14 @@ impl Session {
}

pub(crate) fn file_path(&self, url: &lsp_types::Url) -> Result<RomePath> {
let mut path_to_file = url
.to_file_path()
.map_err(|()| anyhow!("failed to convert {url} to a filesystem path"))?;
let mut path_to_file = match url.to_file_path() {
Err(_) => {
// If we can't create a path, it's probably because the file doesn't exist.
// It can be a newly created file that it's not on disk
PathBuf::from(url.path())
}
Ok(path) => path,
};

let relative_path = self.initialize_params.get().and_then(|initialize_params| {
let root_uri = initialize_params.root_uri.as_ref()?;
Expand Down