-
-
Notifications
You must be signed in to change notification settings - Fork 84
Initial lua support #1962
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
Initial lua support #1962
Conversation
I have a query like this for matching names (and a similar one for values):
Originally I wanted to only use an additional line EDIT: Specific case above doesn't actually matter now, because due to new chuck behavior they have to be different queries anyways. But still curious about the general problem of applying a domain to a query that isn't actually capturing anything itself. |
I was starting to work on the Atm for lua if I have This behavior is consistent with:
However, javascript and typescript are different: Should we make sure all of these languages are actually consistent? It seems like a generic enough coding construct that it seems like it should be consistent across cursorless. I think it's probably reasonable to just follow the way it works in js/ts, so I'm tempted to do that for lua as well, but maybe this discussion already took place when whoever implemented rust and cpp did it. |
Typescript is our reference language and ideally the other languages would mirror typescripts behavior went appropriate. |
Yeah those other languages just haven't been updated to next gen scopes. It's harder to do that fancy removal stuff in our legacy scope defs |
Seems there isn't a way to target the 'let / const' part in ts or 'global' scope part in python. I couldnt find any issues talking about this from a quick scan either, just curious what the thoughts are on why that doesnt exist or if there are plans. Lua uses 'local' for variable scoping and it seems that type of syntax might be a useful target too? Like 'scope' or something. |
8513858
to
5c56744
Compare
I think this is probably good for review now and has most of what's needed. Possibly some missing iterations and domains and weird edge cases I didn't think of. Two small things: First, I didn't bother trying to play with the Second, even though lua doesn't support a ternary, there is an idiomatic equivalent which is of the form |
I just realized I forgot to add multi-line string support, which won't work with the existing cursorless string parsing, similar to what I ran into for nix. lua uses I did actually add support for language-specific overrides in the nix PR #1911 . I could break that logic out into a separate PR so that this could benefit from it early, or can wait to implement lua multi-line string support after the nix PR lands. |
I would be tempted to do that, because a) we prefer atomic PRs to the extent practical, and b) that PR has lots of interesting discussion points 😅 |
Up to you; if you think it would be useful, go for it
Hmm. Agreed it feels a bit special. I could go either way |
Maybe? You can always get it using "first token state" or just a hat |
I love your support tables; filed #2010 to discuss how to formalize them |
Created PR #2012, though may not be quite as easy as planned. |
|
I can definitely see the logic, but I do wonder if we want to include end |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, fantastic first ante here. I left some comments using screenshots above. I haven't reviewed your .scm
file in any detail as I figured we might want to discuss the behaviour mentioned in the screenshots first
Finally able to take a look at your responses. My reasoning was that
I can say
I can say If I include |
@josharian @AndreasArvidsson see above re "branch". I know you guys have stronger opinions on branch ranges than I do 😅 |
Ok I factored out a couple semi-independent changes: I kept the code here too, but presuming those PRs don't change much before merge, we should be able to cleanly merge as the changes will be identical |
Thanks for that, it's a lot cleaner. I should finally have time to start revisiting those other PRs soon, so will apply this style to them soon.
I intend to start porting the old tests to the new facet tests pretty much right away, but as I know at least saidelike wants to start using the lua grammar asap, I feel like they can wait for a follow up PR if that's good with you.
I just fixed those, so hopefully it's good to go as is. I guess I learned by lesson not to force push lol, as I have no idea where that code went... I have a habit to git rebase and not merge, but my workflow doesn't work so well for PRs it seems. I guess you usually Suppose I should note there is still #2012, but imo that isn't really blocking for lua atm as I've been using it for a lua project for a bit and is working well. I guess I should note I'm gonna have to learn typescript and setup proper cursorless extension debugging and what not to help work on cursorless-neovim, so it may be that I can fix #2012 myself too once that's working |
looks like there's a bunch of test failures. I think maybe you need to add an entry to https://github.com/cursorless-dev/cursorless/blob/main/packages/common/src/extensionDependencies.ts so that CI installs a Lua extension |
That didn't work, so will have to revert it I guess. I noticed here that lua is a default known identifier... Seems almost as if lua.scm isn't getting picked up, but I don't see why it wouldn't be detected like every other language, after looking through LanguageDefinitions.ts |
I've got something setup so I can run the github workflows locally using act, so hopefully can try to jump into the docker instance and poke around a bit... |
Running the workflows locally didn't end up helping so far unfortunately, as they fail for different reasons I haven't been able to fix yet. One thing I realized though is that the nix lang support tests are passing... If there was any one of the pull requests that I would expect to be failing for the languageId not existing it would be that one, so I'm at a bit of a loss as to why this one isn't working. |
ah right in that case yeah I'd roll back your change. Nice find |
that's because it installs nix dependency https://github.com/cursorless-dev/cursorless/pull/1911/files#diff-22615f93d65e3ad864e07dbd196d6094287fc773d4daa41f6f275bf1ee029f7e |
what happens when you run tests locally without act? Ie according to instructions in contributor guide? |
Running the lua subset tests, I get three test errors, and the rest pass. But the three errors are seemingly totally unrelated to the github workflow errors:
and
Not sure why yet. |
This reverts commit 06aae3b.
Ya, so after fixing the other errors (had to do with direnv and vscode issues again), all the lua tests pass locally. I also don't have any special extensions loaded into the dev profile for vscode, command-server, parse tree, and nix.. so seems to be a github workflow only issue |
I was going through the failed test log again and noticed a lot earlier than the actual flagged red errors there was lots of complaints from lua.scm about @dummy being invalid identifier, and then noticed you folks used @_dummy not @dummy in your .scm files, so I just switched it to @_dummy and it resolved the languageId problem errors later on. but now other specific lua tests are failing. maybe worth having a pre-commit checker or other check somewhere to prevent use of invalid identifiers like @dummy fwiw I think the new test failures are all for the new style scope facet tests, which my subset test run locally wasn't using, so will investigate that next. forgot you had to run those tests separately. |
I'm out of ideas again. The facet coverage tests do all pass on my system (and were running):
The error output from the failing test log that show the actual and expected look identical to me too, so not sure what it's running into |
we changed fixture format so just run the update fixtures launch config locally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's ship it!
## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet
This is me breaking out some functionality that was part of PR #1911 since that PR has lots of work to be done and it may still benefit other languages that get in sooner. I've applied the suggested changes from pokey in that PR's code review. I've also added a placeholder map for lua which uses `[[ ]]` for multiline support as noted in PR #1962, however I realized as I went to add it that it's not as simple as the way I did it for nix because I can't just reuse the existing `singleQuote` entry since lua actually uses single quotes. So this may actually be a bit harder, and reminds me of [this discussion](#1992 (comment)). So before I go randomly hacking stuff I'm curious what you think the best approach here is. These are the comments I had left in the Nix PR about these changes: * I called returning delimiterToText as getSimpleDelimiterMap to kind of mirror complexDelimiterMap. * I'm not sure is if you still want a delimiterMap.ts standalone file, and then a getSimpleDelimiterMap.ts only for that function. Now delimiterToText isn't referenced anywhere else, so seemed maybe okay to keep them together. * I also thought about adding getComplexDelimiterMap(), but atm because complexDelimiterMap only ever uses the keys from the delimiterToText it won't change even if the language has different values, so seemed unnecessary. These are all things I could guess at your preferences, but may as well ask instead. * I also noticed leftToRightMap in that file isn't actually used anywhere so can be deleted I think, but also not sure about doing that as part of a totally unrelated code change, to keep commits clean. ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [x] I have not broken the cheatsheet --------- Co-authored-by: fidgetingbits <[email protected]> Co-authored-by: Pokey Rule <[email protected]>
What
Adds support for the
lua
programming languageChecklist
"change"
/"clear"
instead of"take"
for selection tests to make recorded tests easier to read"chuck"
instead of"change"
to test removal behaviour when it's interesting, especially:"chuck arg"
with single argument in list"chuck arg"
with multiple arguments in list"chuck item"
with single argument in list"chuck item"
with multiple arguments in list@textFragment
captures. Usually you want to put these on comment and string nodes. This enables"take round"
to work within comments and strings."change round"
inside a string, eg"hello (there)"
"type"
both for type annotations (egfoo: string
) and declarations (eginterface Foo {}
) (and added tests for this behaviour 😊)"item"
both for map pairs and list entries (with tests of course)Scope Support
list
@list
inside list
@list.interior
map
@map
inside map
@map.interior
key
@collectionKey
funk
@namedFunction
inside funk
@namedFunction.interior
funk name
@functionName
lambda
@anonymousFunction
inside lambda
@anonymousFunction.interior
name
@name
value
@value
value
@value
value
@value
state
@statement
if state
@ifStatement
condition
@condition
condition
@condition
condition
@condition
condition
@condition
condition
@condition
branch
@branch
comment
@comment
string
@string
string
@string
@textFragment
call
@functionCall
callee
@functionCallee
arg
@argumentOrParameter
class
@class
inside class
@class.interior
class name
@className
type
@type