Skip to content

Commit

Permalink
fix formatting of unsaved changes by using vfs instead of real fs
Browse files Browse the repository at this point in the history
  • Loading branch information
vemoo committed Mar 28, 2024
1 parent 2ee07a5 commit 309ab21
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions kclvm/tools/src/LSP/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,21 @@ pub(crate) fn handle_semantic_tokens_full(
}

pub(crate) fn handle_formatting(
_snapshot: LanguageServerSnapshot,
snapshot: LanguageServerSnapshot,
params: lsp_types::DocumentFormattingParams,
_sender: Sender<Task>,
) -> anyhow::Result<Option<Vec<TextEdit>>> {
let file = file_path_from_url(&params.text_document.uri)?;
let src = std::fs::read_to_string(file.clone())?;
let path = from_lsp::abs_path(&params.text_document.uri)?;
let src = {
let vfs = snapshot.vfs.read();
let file_id = vfs
.file_id(&path.into())
.ok_or(anyhow::anyhow!("Already checked that the file_id exists!"))?;

String::from_utf8(vfs.file_contents(file_id).to_vec())?
};

format(file, src, None)
}

Expand Down

0 comments on commit 309ab21

Please sign in to comment.