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

[Go] Fix compiler directive syntax patterns #3242

Merged
merged 13 commits into from
Mar 6, 2022

Conversation

kortschak
Copy link
Contributor

@kortschak kortschak commented Feb 20, 2022

This adds line and export directive syntax patterns and generalises the //go:name pattern for use in other contexts such as linter directives. It also fixes //go:name matching to avoid matching invalid directive comments.

It's not completely clear to me how to express the expectation in the tests (and some current tests expectation are incorrect; //go and //go: are invalid directives — so I expect tests to fail), so please let me know what I should add.

These should be marked as valid directives:

//go:linkname
//go:cgo_import_dynamic
//lint:ignore U1000 This is here for user documentation.
//lint:ignore-file Autogenerated.
//line file.rl:3732:45
//line :3732:45:45
//line :3732 :45:45
/*line file.rl:3732:45*/
/*line :3732:45:45*/
/*line :3732 :45:45*/
//export myfunc
//extern myfunc

These should not be marked:

/*line file.rl:3732:45 */
/*line :3732:45:45 */
/*line :3732 :45:45 */
//go:
//go

Please take a look.

@kortschak kortschak force-pushed the directives branch 2 times, most recently from 6199955 to 6c8f18e Compare February 20, 2022 09:22
This adds line and export directive syntax patterns and generalises the
//go:name pattern for use in other contexts such as linter directives. It
also fixes //go:name matching to avoid matching invalid directive comments.
@jrappen
Copy link
Contributor

jrappen commented Feb 21, 2022

In general, capturing regex groups should not be part of variables in the syntax. This is mainly for readability reasons.

Instead use the variables within a capturing group of the match in the contexts.

@jrappen
Copy link
Contributor

jrappen commented Feb 21, 2022

Additionally, you should probably add "negative tests" for the examples listed above, where markings should not be applied.

Edit: I somehow didn't see the negative tests for //go and //go: towards the top of the suggested changes.

@kortschak
Copy link
Contributor Author

Additionally, you should probably add "negative tests" for the examples listed above, where markings should not be applied.

These are included.

@kortschak
Copy link
Contributor Author

kortschak commented Feb 21, 2022

In general, capturing regex groups should not be part of variables in the syntax. This is mainly for readability reasons.

In this case (line directive) this either declarifies the use site or breaks the rationale for the pattern, but I will change it.

jrappen
jrappen previously approved these changes Feb 21, 2022
@jrappen
Copy link
Contributor

jrappen commented Feb 21, 2022

This seems fine. I don't use Go, though.

Go/Go.sublime-syntax Outdated Show resolved Hide resolved
michaelblyons
michaelblyons previously approved these changes Feb 22, 2022
@kortschak
Copy link
Contributor Author

Looking at golang/go#43776, and noting the existence of //go-sumtype: as a namespace, I think it's worth generalising the pattern.

Go/Go.sublime-syntax Outdated Show resolved Hide resolved
Go/Go.sublime-syntax Outdated Show resolved Hide resolved
Go/Go.sublime-syntax Outdated Show resolved Hide resolved
Go/Go.sublime-syntax Outdated Show resolved Hide resolved
@deathaxe
Copy link
Collaborator

deathaxe commented Mar 1, 2022

I'd vote to avoid stacking meta.annotation and meta.annotation.parameters. Added a proposal to the branch accordingly. Feel free to further tweak it.

Go/Go.sublime-syntax Outdated Show resolved Hide resolved
@kortschak
Copy link
Contributor Author

kortschak commented Mar 6, 2022

Please revert c41f4ea, it was better before that, or alternatively (preferably) have a punctuation for the space (I looked for whether there would be an obvious way to specify a space as punctuation, but I could not see a label that fit).

Pattern like so ((//)(line)( ))([a-zA-Z0-9. :]*(?::[0-9]+){1,2})$\n?

@deathaxe
Copy link
Collaborator

deathaxe commented Mar 6, 2022

We could scope whitespace as punctuation but only background colors could be applied. Not sure if it's worth it.

@kortschak
Copy link
Contributor Author

The reason I think it should be like that is if people are using background to separately mark the function from the parameters, that will bleed into the space. I don't use background, but I do mark the function differently to the parameters.

@kortschak
Copy link
Contributor Author

Sorry, clobbered your commit. The naming of the space can be changed to suit.

@deathaxe deathaxe requested a review from michaelblyons March 6, 2022 18:25
@deathaxe deathaxe merged commit a49bdef into sublimehq:master Mar 6, 2022
@kortschak
Copy link
Contributor Author

@deathaxe Thank you for your help and patience with this.

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.

5 participants