Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit d760547

Browse files
authored
match upstream typstfmt config file names (#475)
1 parent 69cdef3 commit d760547

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/server/formatting.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use anyhow::anyhow;
2+
use futures::future::TryFutureExt;
23
use tower_lsp::lsp_types::{Position, Range, Registration, TextEdit, Unregistration};
3-
use typst::syntax::{FileId, Source, VirtualPath};
4+
use typst::{
5+
foundations::Bytes,
6+
syntax::{FileId, Source, VirtualPath},
7+
};
48
use typstfmt_lib::Config;
59

6-
use crate::workspace::project::Project;
10+
use crate::workspace::{fs::FsResult, project::Project};
711

812
use super::TypstServer;
913

1014
const FORMATTING_REGISTRATION_ID: &str = "formatting";
1115
const DOCUMENT_FORMATTING_METHOD_ID: &str = "textDocument/formatting";
12-
const CONFIG_PATH: &str = "typstfmt-config.toml";
16+
const CONFIG_PATH: &str = "typstfmt.toml";
1317

1418
pub fn get_formatting_registration() -> Registration {
1519
Registration {
@@ -59,8 +63,15 @@ async fn get_config(project: &Project) -> anyhow::Result<Config> {
5963
}
6064

6165
async fn config_from_file(project: &Project) -> Option<anyhow::Result<Config>> {
62-
let file_id = FileId::new(None, VirtualPath::new(CONFIG_PATH));
63-
let file = project.read_bytes_by_id(file_id).await.ok()?;
66+
async fn read_file(project: &Project, path: &str) -> FsResult<Bytes> {
67+
let file_id = FileId::new(None, VirtualPath::new(path));
68+
project.read_bytes_by_id(file_id).await
69+
}
70+
71+
let file = read_file(project, CONFIG_PATH)
72+
.or_else(|_| async { read_file(project, &format!(".{CONFIG_PATH}")).await })
73+
.await
74+
.ok()?;
6475
let bytes = file.as_slice();
6576
Some(config_from_bytes(bytes))
6677
}

0 commit comments

Comments
 (0)