Skip to content

pony-lsp: Pass AST after every pass to lsp#5227

Open
mfelsche wants to merge 4 commits into
mainfrom
pony_compiler-pass-interface
Open

pony-lsp: Pass AST after every pass to lsp#5227
mfelsche wants to merge 4 commits into
mainfrom
pony_compiler-pass-interface

Conversation

@mfelsche
Copy link
Copy Markdown
Contributor

For now only finer detailed compilation progress reporting, but also as a preparation for investigating the AST in earlier stages, e.g. right after parsing for replacing text based analysis.

For now only finer detailed compilation progress reporting,
but also as a preparation for investigating the AST in earlier stages, e.g. right after parsing
for replacing text based analysis.
@mfelsche mfelsche requested a review from orien April 11, 2026 20:22
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 11, 2026
@SeanTAllen
Copy link
Copy Markdown
Member

So what is this building towards?

@mfelsche
Copy link
Copy Markdown
Contributor Author

It makes the Program available to the WorkspaceManager after the parse pass (and other passes), so we e.g. can evaluate if we have variable declarations with assignment or without without re-parsing text lines. Or we might be able to unfuck the AST when it comes to partial application or object literals, as these are not replaced with references to synthetically created class/actor definitions after the parse pass. Previously the pony-lsp only got the ast after the finaliser pass.

Stuff like this, where all the passes messed up the actual AST, that makes it hard to analyze it.

@SeanTAllen
Copy link
Copy Markdown
Member

@mfelsche ack

@orien
Copy link
Copy Markdown
Member

orien commented Apr 11, 2026

There is a lot of direct source code scanning in the inlay hints feature, see #5222. I'd love to replace that with AST analysis. So I'm very happy to see this.

Copy link
Copy Markdown
Member

@orien orien left a comment

Choose a reason for hiding this comment

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

Thanks for pursuing this 🙇

I'm not super familiar with the compilation process. So I have some questions.

Comment on lines -279 to -288
elseif this._client.supports_workspace_diagnostic_refresh() then
// we only need to issue a refresh if
// the client doesn't support publish
// diagnostics

// tell the client to refresh all
// diagnostics for us
this._request_sender.send_request(
Methods.workspace().diagnostic().refresh(),
None)
Copy link
Copy Markdown
Member

@orien orien Apr 11, 2026

Choose a reason for hiding this comment

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

Do we still want to support this class of client?

Comment thread tools/pony-lsp/workspace/workspace_manager.pony Outdated
Comment thread tools/pony-lsp/workspace/state.pony Outdated
Comment on lines +190 to +191
// group errors by file
let errors_by_file = Map[String, pc.Vec[JsonValue]].create()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To prevent unnecessary allocations, can we move this into the if done_compiling then block below?

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 will add a prealloc of 0 to create() in order to have no additional allocation when compilation is not done yet.

Comment on lines +184 to +188
// notify client about progress
let notification = this._progress_report_nofitication(program_dir, pass)
if this._client.supports_window_work_done_progress() then
this._channel.send(notification)
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we move the notification creation into the conditional block?

paths: Array[String val] val,
notify: CompilerNotify tag)
notify: CompilerNotify tag,
notify_passes: Array[PassId] val = [PassFinaliser])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The trait definition of this behavior doesn't include the default value. Is that a problem?

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 don't think so.

Comment on lines +252 to +256
| (let program: Program val, PassParse) =>
// parsing was successful
// TODO: use parse pass data already
// to pre-fill some package and module states
None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You mentioned that some of this data is mutable. Should we be worried about accessing it?

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.

yeah, you are absolutely right, the PonyCompiler actor is mutating the AST in parralel, while we are accessing it here. The compilation process needs to happen within the WorkspaceManager. I will change this, pls do not merge.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added a "do not merge" label as requested in the comment above

mfelsche and others added 2 commits April 12, 2026 14:53
Co-authored-by: Orien Madgwick <497874+orien@users.noreply.github.com>
Co-authored-by: Orien Madgwick <497874+orien@users.noreply.github.com>
@jemc jemc added the do not merge This PR should not be merged at this time label Apr 22, 2026
@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge This PR should not be merged at this time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants