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
1 change: 1 addition & 0 deletions rust/Cargo.lock

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

45 changes: 43 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ or removing a command fails until the table changes in the same commit.
| `lsp.mergeCompletions` | Choose which candidates survive when several prioritized providers complete at one position |
| `lsp.activationPolicy` | Decide whether a language server may start automatically after failures, using a platform monotonic clock |
| `lsp.problems.query` | Filter, order, and group Problems tool-window diagnostics and count them by severity |
| `lsp.references.query` | Group Find Usages locations by file and lay out the References tool window's visible rows, selection, and previous/next usages |
| `lsp.references.lines` | Show the lines of References tool-window usages with highlighted usage ranges, as search results show theirs |
| `lsp.startServer` | Start one Rust-owned process/session and begin initialization |
| `lsp.stopServer` | Gracefully shut down a session, with a bounded force-stop fallback |
| `lsp.updateWorkspaceConfiguration` | Replace the plugin configuration a running plugin-owned session answers `workspace/configuration` with, and announce it |
Expand Down Expand Up @@ -2290,8 +2292,12 @@ Optional `includePathPatterns`, `excludePathPatterns`, and `pathFilterPrefix`
filter paths before the page limit. Patterns are case-insensitive glob fragments:
`*` excludes separators, `**` crosses them, and `?` matches one non-separator.
When `includeContentRanges` is true, content matches also return the original
`sourceLine` and `contentMatchRanges` in UTF-16 units; existing callers keep the
trimmed `preview` and do not pay for those fields.
`sourceLine` and `contentMatchRanges` in UTF-16 units, and `preview` becomes the
result row's line with `previewRanges` (UTF-16 `{ start, length }` inside
`preview`): indentation and line break dropped and, when the first match starts
more than 32 units in, the front cut and replaced by `…`, the same rule
`lsp.references.lines` applies. Existing callers keep the trimmed `preview`
and do not pay for those fields.

Observed `workspace.searchEverywhere` calls may emit
`{ "type": "searchResults", "operationId": "…", "results": { "matches": […] } }`
Expand Down Expand Up @@ -2977,6 +2983,41 @@ the Project view's natural file-name order. Severity is the LSP number;
missing or out-of-range values are unknown (`0`) and rank last. Cases:
`rust/fixtures/lsp/problems-query-v1.json`.

`lsp.references.query` accepts the Find Usages answer as
`{ locations: [{ fileKey, displayPath, line, column }] }` together with the
platform-held tree state: `rootCollapsed`, `collapsed` (the `fileKey`s of
closed file nodes; unknown keys are ignored), and the `selected` row key. It
returns `groups` (one per file in the natural file-name order of
`displayPath`, each with `key` `file:<fileKey>`, `fileKey`, `displayPath`,
`name`, `folder`, and `indices` into the submitted list ordered by line and
column, then submission order) and `rows`, the rows that show from top to
bottom. A row has `key` (`root`, `file:<fileKey>`, or `usage:<index>`),
`kind` (`root`, `file`, `usage`), `depth`, `expanded` (nodes only), `group`
(files and usages), `shows` (the usage the row previews and opens: itself, or
the first usage under a node), and `previous`/`next` (the usages before and
after it in tree order, counting usages under closed nodes; absent at the
ends), so the platform steps through usages without another call. `selected`
and `selectedRow` name the selected row: an unknown or absent key selects the
first usage, and a row a closed node hides moves the selection to that node.
An empty answer returns no rows and no selection. Every location is kept;
none is filtered or merged with another on the same line. The platform keeps
the tree state, focus, and file reading, and queries again after a new
answer or an expand, collapse, or selection change. Cases:
`rust/fixtures/lsp/references-query-v1.json`.

`lsp.references.lines` accepts `{ texts, usages: [{ text, line, column,
endLine, endColumn }] }`, where `text` indexes the distinct line texts (so a
long line with several usages crosses the boundary once) and positions are
zero-based UTF-16. It returns one `{ text, ranges: [{ start, length }] }` per
usage, in order. The usage is highlighted from `column` to `endColumn` on its
line, or to the end of the line when it runs onto later lines; an empty or
reversed range is not highlighted. The line is shown with the rule of search
result rows (`lithe_text::line_preview`): indentation and line break dropped,
the front cut and replaced by `…` when the usage starts more than 32 units in
(16 units stay before it), and the text bounded to 240 bytes at a character
boundary. A `text` index past `texts` is `invalid_request`. Cases:
`rust/fixtures/lsp/references-lines-v1.json`.

Core ships no built-in language-provider catalog. Every language server comes
from a plugin's `languageServers` declaration, which Core validates and plans.

Expand Down
7 changes: 7 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ pub enum LspCommand {
ActivationPolicy,
/// Filters, orders, and groups Problems tool-window diagnostics (`lsp.problems.query`).
ProblemsQuery,
/// Groups Find Usages locations by file and lays out the References tool
/// window's rows (`lsp.references.query`).
ReferencesQuery,
/// Shows the lines of References tool-window usages (`lsp.references.lines`).
ReferencesLines,
/// Starts and initializes a managed language server (`lsp.startServer`).
StartServer,
/// Gracefully shuts down a managed server (`lsp.stopServer`).
Expand Down Expand Up @@ -1351,6 +1356,8 @@ impl CoreCommand {
"lsp.mergeCompletions" => Some(Self::Lsp(LspCommand::MergeCompletions)),
"lsp.activationPolicy" => Some(Self::Lsp(LspCommand::ActivationPolicy)),
"lsp.problems.query" => Some(Self::Lsp(LspCommand::ProblemsQuery)),
"lsp.references.query" => Some(Self::Lsp(LspCommand::ReferencesQuery)),
"lsp.references.lines" => Some(Self::Lsp(LspCommand::ReferencesLines)),
"lsp.startServer" => Some(Self::Lsp(LspCommand::StartServer)),
"lsp.stopServer" => Some(Self::Lsp(LspCommand::StopServer)),
"lsp.updateWorkspaceConfiguration" => {
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ pub(super) fn dispatch(command: LspCommand, id: Option<String>, payload: Value)
LspCommand::ProblemsQuery => {
plugin_response(id, payload, lithe_lsp_policy::problems::query_command)
}
LspCommand::ReferencesQuery => {
plugin_response(id, payload, lithe_lsp_policy::references::query_command)
}
LspCommand::ReferencesLines => {
plugin_response(id, payload, lithe_lsp_policy::references::lines_command)
}
LspCommand::StartServer => {
match serde_json::from_value::<lithe_lsp_engine::StartServerRequest>(payload)
.map_err(|error| {
Expand Down
28 changes: 28 additions & 0 deletions rust/crates/core/src/tests/lsp_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ fn problems_query_matches_shared_fixture() {
);
}

#[test]
fn references_query_matches_shared_fixture() {
run_fixture(
"lsp.references.query",
include_str!("../../../../fixtures/lsp/references-query-v1.json"),
);
}

#[test]
fn references_lines_matches_shared_fixture() {
run_fixture(
"lsp.references.lines",
include_str!("../../../../fixtures/lsp/references-lines-v1.json"),
);
}

#[test]
fn activation_policy_matches_shared_fixture() {
let fixture: Value = serde_json::from_str(include_str!(
Expand Down Expand Up @@ -128,6 +144,18 @@ fn malformed_requests_fail_with_invalid_request() {
"lsp.problems.query",
json!({"diagnostics": [], "groupBy": "type"}),
),
(
"lsp.references.query",
json!({"locations": [{"fileKey": "a"}]}),
),
(
"lsp.references.query",
json!({"locations": [], "expanded": []}),
),
(
"lsp.references.lines",
json!({"texts": [], "usages": [{"text": 0, "line": 0, "column": 0, "endLine": 0, "endColumn": 1}]}),
),
("lsp.activationPolicy", json!({"event": "automaticStart"})),
(
"lsp.activationPolicy",
Expand Down
9 changes: 9 additions & 0 deletions rust/crates/core/src/tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,15 @@ fn search_pages_apply_path_filters_before_the_page_limit() {
first["data"]["matches"][0]["contentMatchRanges"],
case["expected"]["contentMatchRanges"]
);
// The row's line drops the indentation and keeps the match marked in it.
assert_eq!(
first["data"]["matches"][0]["preview"],
case["expected"]["preview"]
);
assert_eq!(
first["data"]["matches"][0]["previewRanges"],
case["expected"]["previewRanges"]
);
payload["cursor"] = first["data"]["nextCursor"].clone();
assert!(payload["cursor"].is_string());
let second = call(&payload);
Expand Down
3 changes: 2 additions & 1 deletion rust/crates/lsp-policy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ name = "lithe-lsp-policy"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
description = "Deterministic language-tooling decisions both platform hosts apply: document identity, navigation targets, workspace edit plans, completion merging, activation and problems queries"
description = "Deterministic language-tooling decisions both platform hosts apply: document identity, navigation targets, workspace edit plans, completion merging, activation, and the Problems and References tool-window queries"

[dependencies]
lithe-core-rules = { path = "../core-rules" }
lithe-document-uri = { path = "../document-uri" }
lithe-platform = { path = "../platform" }
lithe-protocol = { path = "../protocol" }
lithe-text = { path = "../text" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
url = "2.5"
1 change: 1 addition & 0 deletions rust/crates/lsp-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ pub mod declaration_or_usages;
pub mod document_identity;
pub mod navigation_target;
pub mod problems;
pub mod references;
pub mod workspace_edit_plan;
mod workspace_scope;
Loading
Loading