Skip to content
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

feat: add query for nushell #438

Merged
merged 4 commits into from
Jan 5, 2025
Merged

Conversation

melMass
Copy link
Contributor

@melMass melMass commented Jan 1, 2025

This adds basic symbol support for nushell

outliner-queries-nushell.mp4

I'm also curious about two things:

  • Is there a way to provide a literal @name ? For instance I wanted to collect nushell's export-env that don't have name, (I tried (#set! "name" "MyName") but it still returns Anonymous):
export-env {
    $env.STEVE = arc
}
(decl_export
  (#set! "kind" "Module")
) @symbol
  • Is there a way to provide custom HL? I would for instance use it to differentiate export def and export --env def, the later is allowed to modify the caller's environment variables

@github-actions github-actions bot requested a review from stevearc January 1, 2025 19:38
Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

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

Could you add a test file to this directory https://github.com/stevearc/aerial.nvim/tree/master/tests/treesitter and update the snapshots with make update_snapshots and confirm that the symbols look correct?

Is there a way to provide a literal @name?

No, but you can add all kinds of custom behavior via an extension in extensions.lua. Would that serve your purpose?

Is there a way to provide custom HL?

No, because all the highlight groups have to be defined and well known so that users can supply their own overrides. This isn't a concept that maps to other languages, so there's nothing in the current highlight groups that would support it.

@melMass
Copy link
Contributor Author

melMass commented Jan 4, 2025

Nice! Yep I realized right after submitting the PR and by a quick look couldn't tell how it worked, I'll do it now!

I'll check extensions I wasn't aware of this mechanism, but like that it definitely seems like what I was after!

@melMass
Copy link
Contributor Author

melMass commented Jan 4, 2025

I made the update, strangely locally: groovy, julia, lua, ruby, ruby_singleton & swift returned a different "snapshot"

Some notes on potential future improvements:

  • I used Interface for const exports, this isn't really a concept I could find in other languages.
  • It would be great to be able to differentiate "private" (non exported def) and public defs
  • I wanted to include other things in the tree but since they are unnamed in nushell it didn't look great, and again some concepts aren't easily mappable to other langs.
    I believe extension could easily solve that but to list them:
    • export-env: block is exported into the env of the importer (top level symbol)
    • load-env: block is loaded in the caller env (non top level symbol)
    • differentiate from def and def --env: the later can modify the caller's env variables

@github-actions github-actions bot requested a review from stevearc January 4, 2025 02:08
@melMass
Copy link
Contributor Author

melMass commented Jan 4, 2025

Yep playing around with extensions there is surely and nifty way to solve all the cases I mentioned but that's definitely better in a dedicated PR

@stevearc
Copy link
Owner

stevearc commented Jan 4, 2025

I used Interface for const exports, this isn't really a concept I could find in other languages.

Would Constant work better for this? See the available SymbolKinds in the LSP specification

It would be great to be able to differentiate "private" (non exported def) and public defs

There are a couple of languages that support @scope. Check out how we're doing that for ruby.

To get that test to pass, it looks like you'll need to add a filetype rule to the test setup

extension = {
just = "just",
norg = "norg",
objdump = "objdump",
usd = "usd",
usda = "usd",
smk = "snakemake",
dj = "djot",
},

@melMass
Copy link
Contributor Author

melMass commented Jan 5, 2025

Would Constant work better for this?

Yep I will change it, my logic was that Constant isn't part of the default symbols (and you probably don't want it in the tree of most lang)

There are a couple of languages that support @scope. Check out how we're doing that for ruby.

Interesting! I will need more experience with queries (and live experiment with it) to grasp what's possible as like that I don't fully understand all the syntax used

@stevearc
Copy link
Owner

stevearc commented Jan 5, 2025

Looks good, thanks for the PR!

@stevearc stevearc merged commit 4c0c3bd into stevearc:master Jan 5, 2025
8 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