Skip to content

Conversation

geordiekorper
Copy link
Contributor

@geordiekorper geordiekorper commented Aug 20, 2025

This PR adds document outline support for AppleScript and JXA files, enabling developers to navigate their code more efficiently through VSCode's Outline view.

What's New

  • Document Symbol Providers: Implemented symbol providers for both AppleScript and JXA languages
  • Function/Handler Detection: Automatically detects and displays:
    • Functions (on, to)
    • Script handlers (e.g., on run, on open)
    • Nested function structures
  • Hierarchical Navigation: Properly structures nested functions in the outline tree

Bug Fixes

  • Fixed duplicate symbol generation that was causing handlers to appear twice in the outline
  • All changes now pass linting with Biome 2.2.0

Technical Details

  • Added src/outline.ts with comprehensive parsing logic for AppleScript/JXA syntax
  • Parser handles:
    • Multi-line function declarations
    • Both block comment styles ((* *) and -- )
    • Nested function blocks with proper parent-child relationships
    • Entry point detection for script handlers
  • Registered symbol providers in the extension activation
  • Added appropriate language activation events
  • JXA files leverage VSCode's existing JavaScript parsing for accuracy

Changes

  • New file: src/outline.ts - Complete outline implementation (750+ lines)
  • Modified: src/index.ts - Register document symbol providers
  • Modified: package.json - Add activation events for AppleScript and JXA
  • Modified: src/processes.ts - Fix lint error (map→forEach)
  • Updated: biome.jsonc - Update to Biome 2.2.0 for compatibility
  • Updated: pnpm-lock.yaml - Biome dependency update

Testing

The outline functionality has been tested with various AppleScript and JXA files, including:

  • Simple function definitions
  • Nested handlers
  • Scripts with multiple entry points
  • Unit tests were created and run but not submitted due to lack of testing framework in upstream repo

Impact

This is a non-breaking enhancement that adds new functionality without modifying existing features.
Users will immediately see an Outline view populated with their script's structure when opening
AppleScript or JXA files.

- Add document symbol providers for outline view
- Implement function/handler detection and parsing
- Add activation events for AppleScript and JXA languages
- Enhance documentation for FunctionBlock interface
The appleScriptSymbolProvider was adding function symbols twice:
- Once inside the emitSymbols() function
- Again after calling emitSymbols()

This caused duplicate entries for all handlers/functions in the outline.
- Update Biome from 1.9.4 to 2.2.0 to fix config compatibility
- Remove invalid organizeImports key from biome config
- Fix map/forEach usage in processes.ts (lint error)
- Fix function naming conflict in outline.ts (_makeFuncSymbol)
- Apply import ordering and formatting fixes
@geordiekorper
Copy link
Contributor Author

I saw that the initial CI workflow failed. I have attempted to update the PR to solve that. Apologies for the unclean PR than mixes the biome update in with the feature.

@idleberg
Copy link
Owner

Oh wow, this is awesome. Please allow me a couple of days to properly review it.

@geordiekorper
Copy link
Contributor Author

Ugh I already found a bug. The AppleScript works great but it appears that leveraging VSCode's existing JavaScript parsing for JXA as a passthrough, has problems. For some reason it passes back only the top-level entities which isn't very helpful if the file has classes that have nested functions. Originally I didn't look at the output very closely because I could see the outline view was populated and I assumed that it would have the same output as if the file had a .js extension.

Anyway I have implemented an acorn parser based tree walker that produces output which more closely matches what one would expect. Apologies for not finding the problem earlier. Once I moved onto working on the project, which had made me want to have outline view in the first place, it became blindingly obvious!

Let me know how you would like to proceed in terms of replacing, fixing or creating a second additive PR.

@idleberg
Copy link
Owner

To be honest, I've been thinking about branching out the JXA support into a separate package for the longest time. I never used it, have practically no knowledge about it, and it would make it easier if someone else wants to take over the package. So I guess it would be okay to limit the outline view support to AppleScript.

@geordiekorper
Copy link
Contributor Author

The corrected version is in the PR now. I understand why you might want to break out the JXA stuff to a separate project but doing that might be more work than just leaving it in. Unless you plan to add a lot more features in which case the work of pulling everything apart could eventually pay off. For what it's worth I found that, because they both deal with JSON well, JXA was a good fit when I wanted to access data in Notes.app from something I created in Node.js. If you already know AppleScript and Javascript, it should be trivial to work with JXA if you ever need to.

VariableDeclaration,
WhileStatement,
WithStatement,
} from "../types/acorn-types";
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick: could you please use the full filename, i.e. add the file extension?

@@ -1,10 +1,8 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"organizeImports": {
Copy link
Owner

Choose a reason for hiding this comment

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

Is organizeImports no longer supported in Biome 2.x? You can actually leave this to me, I've updated some of my projects and would love to continue using my config.

@idleberg
Copy link
Owner

idleberg commented Aug 30, 2025

Just to give you an update: I managed to verify the functionality, but I'm not yet through with the review. I really do appreciate the effort!

If you already know AppleScript and Javascript, it should be trivial to work with JXA if you ever need to.

I can only go by what users reported. Seemingly, some are missing some JS features that VSCode provides out of the box or that are provided by other extensions. Ideally, the JXA portion of this extension would inherit all the JavaScript specifics and only provide build commands. Since I only do JavaScript (not JXA), I have no more insights than what others have reported. Maybe a question for you: is the outline view for JXA any different from a JS outline?

@geordiekorper
Copy link
Contributor Author

I did not treat the outline for JXA any different than a JS outline. I suppose one could, but I am not sure it is worth the effort. For example const Notes = Application('Notes') is sort of the equivalent of tell application "Notes" (although without an end tell equivalent). One might want to show Notes as something other than a constant but it didn't seem worth it. Keeping it simple seemed like the best approach. Personally all I really cared about was that I could easily navigate to functions and had a basic idea of what was in them. The only reason I even give the JXA scripts I use a .jxa extension is because I sometimes have other types of javascript files in the same project and it just makes it clear which is which. If you get any feedback that people want something more I am happy to see what I can do. Here is a full example of some JXA with I am pretty sure anybody who know JS and AS can read without any effort:
Screenshot 2025-09-01 at 4 41 35 PM

@idleberg
Copy link
Owner

idleberg commented Sep 6, 2025

I think this was a misunderstanding. I appreciate you recreating the JS functionality for JXA. I was just thinking that in an ideal world this wouldn't be necessary and some VSCode API would allow you to inherit the functionality from JavaScript (rather than maintaining it yourself and playing catch up).

Anyway, how would you feel about me merging the PR as-is and I will take care of the remaining issues (e.g. the broken pipeline and my change request).

@geordiekorper
Copy link
Contributor Author

geordiekorper commented Sep 6, 2025 via email

@idleberg idleberg merged commit 5300b21 into idleberg:main Sep 9, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants