Skip to content

Separate editor state (OpenFile) from analysis state (File)#1274

Merged
lionel- merged 17 commits into
mainfrom
oak/salsa-31-open-file
Jun 19, 2026
Merged

Separate editor state (OpenFile) from analysis state (File)#1274
lionel- merged 17 commits into
mainfrom
oak/salsa-31-open-file

Conversation

@lionel-

@lionel- lionel- commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Branched from #1271
Progress towards #1212

We were closer than I thought to a cleaner LSP layer file type, so I went ahead and cleaned that up.

  • Rename ArkFile to OpenFile. Now shrunk to editor/transport state (inner: File, version, config, wire_url), dropped the per-file encoding field which can be accessed via LspConfig.
  • Analysis functions now take the bare salsa File instead of &ArkFile. Encoding is read from state.config at the handler boundary.
  • Add state.file(uri) for handlers needing only the File; keep state.open_file(uri) for the two that need wire_url/config (code action, indent)
  • indent_edit and roxygen_documentation now return domain types in tree-sitter coordinates (IndentEdit, RoxygenEdit). LSP conversion happens in the handler.

@DavisVaughan DavisVaughan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few important notes, but seems nice

Comment on lines +20 to +23
/// Free functions over `LineIndex` + `PositionEncoding`, so anything holding
/// those two (a `File` plus its `db`, or a `DocumentContext`) can convert
/// without each carrying its own copy of the logic.
pub(crate) fn lsp_position_from_tree_sitter_point(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, just having free functions feels like the right way to do this to me

Comment thread crates/ark/src/lsp/code_action.rs Outdated
pub(crate) fn code_actions(
db: &dyn ArkDb,
file: &ArkFile,
file: &OpenFile,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we wanted to make this File then it would be pretty complicated

We'd need to return a CodeActionResponse-ish type that we own that doesn't need file.wire_url or file.version but encodes everything else, then at the boundary we'd add in that extra info from the OpenFile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that would be the cleaner way

Comment thread crates/ark/src/lsp/open_file.rs Outdated
Comment on lines +13 to +17
pub(crate) struct OpenFile {
pub(crate) inner: File,
pub(crate) version: Option<i32>,
pub(crate) config: DocumentConfig,
pub(crate) wire_url: Url,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mild preference for not making the fields pub, and instead providing getters for all of them. Most importantly you'd only provide setters for version and config, making it clear that when you call open_file_mut(), those are the only 2 things you are allowed to change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most importantly you'd only provide setters for version and config, making it clear that when you call open_file_mut(), those are the only 2 things you are allowed to change.

That's mildly better, doing that

Comment thread crates/ark/src/lsp/state.rs
Comment thread crates/ark/src/lsp/state.rs Outdated
}

/// The salsa [`File`] handle for an open document.
pub(crate) fn file(&self, uri: &Url) -> anyhow::Result<File> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a bit duplicative to me over something like open_file(uri).file()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, which leads to returning a & from open_file(), which is actually the right thing to do now that it's the long-term API. (We returned an owned value for ArkFile so they can cross r_task())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes strong agree!

Comment thread crates/ark/src/lsp/state_handlers.rs Outdated
Comment thread crates/ark/src/lsp/code_action.rs Outdated
Comment thread crates/ark/src/lsp/code_action.rs Outdated

let indent_size = position.column;
let documentation = documentation_builder(parameter_names, indent_size);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we lost an important We insert the documentation string comment

Comment on lines +190 to +191

roxygen_documentation(
let mut actions = code_actions(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't remove this. This literally doesn't even test the roxygen_documentation() function at all anymore 😢

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same below

@lionel- lionel- Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this dispatches to the roxygen code action right?

@lionel- lionel- force-pushed the oak/salsa-30-lazy-package-metadata branch from bc0615d to 42ad025 Compare June 19, 2026 14:07
Base automatically changed from oak/salsa-30-lazy-package-metadata to main June 19, 2026 14:07
@lionel- lionel- force-pushed the oak/salsa-31-open-file branch from bdbc03d to 30cadc4 Compare June 19, 2026 14:08
@lionel- lionel- merged commit 7cff37b into main Jun 19, 2026
17 checks passed
@lionel- lionel- deleted the oak/salsa-31-open-file branch June 19, 2026 14:39
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants