Skip to content

feat(lsp): add an experimental language server to rari #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
18ed10e
wip
fiji-flo Mar 8, 2025
fddee91
lock
fiji-flo Mar 18, 2025
4d5944f
tree-sitter for md
fiji-flo Mar 18, 2025
5296be3
diagnostics
fiji-flo Mar 19, 2025
9314416
wip
fiji-flo Mar 21, 2025
e7735bf
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo Mar 25, 2025
0a57948
feature
fiji-flo Mar 25, 2025
b12e381
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo Mar 25, 2025
e58ffca
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo May 14, 2025
a3f4121
feat(parser): move to tree-sitter-mdn
fiji-flo May 19, 2025
d6a7d8e
remove peg
fiji-flo May 21, 2025
7186b93
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo May 22, 2025
c6a200a
tree-sitter crate
fiji-flo May 22, 2025
926f765
Merge remote-tracking branch 'upstream/tree-sitter' into lsp
fiji-flo May 22, 2025
538ee6f
wip
fiji-flo May 26, 2025
eb5b413
wip
fiji-flo May 26, 2025
be4bac4
refactor
fiji-flo May 26, 2025
289a4e0
more
fiji-flo May 28, 2025
98f3a3d
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo May 29, 2025
0f52be2
more
fiji-flo Jun 4, 2025
b9c91b6
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo Jun 5, 2025
d20621a
url complete
fiji-flo Jun 10, 2025
cf34c40
doc for link macros
fiji-flo Jun 10, 2025
bb862e0
docs for embeds
fiji-flo Jun 10, 2025
419dbb0
better hover
fiji-flo Jun 10, 2025
d3b55db
Merge remote-tracking branch 'upstream/main' into lsp
fiji-flo Jun 10, 2025
35b2032
fix cssxref
fiji-flo Jun 10, 2025
288647c
no more feature
fiji-flo Jun 10, 2025
bd90e0f
fmt
fiji-flo Jun 10, 2025
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
130 changes: 128 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ members = [
"crates/rari-md",
"crates/rari-doc",
"crates/rari-linter",
"crates/rari-lsp",
"crates/rari-sitemap",
"crates/rari-tools",
"crates/css-syntax",
Expand Down Expand Up @@ -65,6 +66,7 @@ rari-md = { path = "crates/rari-md" }
rari-data = { path = "crates/rari-data" }
rari-templ-func = { path = "crates/rari-templ-func" }
rari-sitemap = { path = "crates/rari-sitemap" }
rari-lsp = { path = "crates/rari-lsp" }

tracing = "0.1"
tracing-subscriber = "0.3"
Expand Down Expand Up @@ -101,6 +103,13 @@ const_format = "0.2"
dialoguer = "0.11"
semver = { version = "1", features = ["serde"] }
strum = { version = "0.27", features = ["derive"] }
tokio = "1"
inventory = "0.3"
tree-sitter-mdn = "0.1"
tree-sitter = "0.23"

[features]
default = []

[dependencies]
rari-doc.workspace = true
Expand All @@ -109,6 +118,8 @@ rari-deps.workspace = true
rari-types.workspace = true
rari-utils.workspace = true
rari-sitemap.workspace = true
rari-lsp.workspace = true


serde.workspace = true
serde_json.workspace = true
Expand All @@ -118,6 +129,7 @@ anyhow.workspace = true
dashmap.workspace = true
schemars.workspace = true
dialoguer.workspace = true
tokio.workspace = true

self_update = { version = "0.42", default-features = false, features = [
"rustls",
Expand All @@ -130,7 +142,6 @@ tabwriter = "1"
axum = "0.8"
tower-http = { version = "0.6", features = ["fs"] }
tower = "0.5"
tokio = "1"
dotenvy = "0.15"

[lints.clippy]
Expand Down
10 changes: 10 additions & 0 deletions crates/rari-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum Commands {
/// Subcommands for altering content programmatically
#[command(subcommand)]
Content(ContentSubcommand),
Lsp,
}

#[derive(Args)]
Expand Down Expand Up @@ -477,6 +478,15 @@ fn main() -> Result<(), Error> {
let _ = SETTINGS.set(settings);
serve::serve()?
}
Commands::Lsp => {
let mut settings = Settings::new()?;
settings.cache_content = true;
settings.data_issues = true;
settings.blog_unpublished = true;
let _ = SETTINGS.set(settings);
read_and_cache_doc_pages()?;
rari_lsp::run()?
}
Commands::GitHistory => {
info!("Gathering history 📜");
let start = std::time::Instant::now();
Expand Down
5 changes: 3 additions & 2 deletions crates/rari-doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ serde_yaml_ng.workspace = true
yaml_parser.workspace = true
schemars.workspace = true
strum.workspace = true
inventory.workspace = true
tree-sitter.workspace = true
tree-sitter-mdn.workspace = true

yaml-rust = "0.4"
percent-encoding = "2"
Expand All @@ -56,8 +59,6 @@ unescaper = "0.1"


css-syntax = { path = "../css-syntax", features = ["rari"] }
tree-sitter-mdn = "0.1"
tree-sitter = "0.23"

[dev-dependencies]
rari-types = { path = "../rari-types", features = ["testing"] }
Expand Down
30 changes: 30 additions & 0 deletions crates/rari-doc/src/find.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use rari_types::locale::Locale;

use crate::cached_readers::{STATIC_DOC_PAGE_FILES, STATIC_DOC_PAGE_TRANSLATED_FILES};
use crate::error::DocError;
use crate::pages::page::Page;

pub fn doc_pages_from_slugish(slugish: &str, locale: Locale) -> Result<Vec<Page>, DocError> {
let cache = if locale == Locale::EnUs {
&STATIC_DOC_PAGE_FILES
} else {
&STATIC_DOC_PAGE_TRANSLATED_FILES
};
cache.get().map_or_else(
|| Err(DocError::FileCacheBroken),
|static_files| {
Ok(static_files
.iter()
.filter_map(|((l, s), v)| {
if locale == *l && s.contains(slugish) {
Some(v)
} else {
None
}
})
.take(100)
.cloned()
.collect())
},
)
}
18 changes: 17 additions & 1 deletion crates/rari-doc/src/html/fix_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,35 @@ pub fn handle_internal_link(
};
if (original_href != resolved_href || remove_href) && !en_us_fallback {
if let Some(pos) = el.get_attribute("data-sourcepos") {
if let Some((start, _)) = pos.split_once('-') {
if let Some((start, end)) = pos.split_once('-') {
if let Some((line, col)) = start.split_once(':') {
let line = line
.parse::<i64>()
.map(|l| l + i64::try_from(page.fm_offset()).unwrap_or(l - 1))
.ok()
.unwrap_or(-1);
let col = col.parse::<i64>().ok().unwrap_or(0);
let (end_line, end_col) = end
.split_once(':')
.map(|(end_line, end_col)| {
let end_line = end_line
.parse::<i64>()
.map(|l| l + i64::try_from(page.fm_offset()).unwrap_or(l - 1))
.ok()
.unwrap_or(-1);
let end_col = end_col.parse::<i64>().ok().unwrap_or(0);
(end_line, end_col)
})
.unwrap_or((-1, -1));
let ic = get_issue_counter();
if remove_href {
tracing::warn!(
source = "broken-link",
ic = ic,
line = line,
col = col,
end_line = end_line,
end_col = end_col,
url = original_href,
);
} else {
Expand All @@ -179,6 +193,8 @@ pub fn handle_internal_link(
ic = ic,
line = line,
col = col,
end_line = end_line,
end_col = end_col,
url = original_href,
redirect = resolved_href
);
Expand Down
Loading
Loading