-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
enh(swift) highlight function and macro call usage #3959
base: main
Are you sure you want to change the base?
enh(swift) highlight function and macro call usage #3959
Conversation
Build Size ReportChanges to minified artifacts in 4 files changedTotal change +241 B View Changes
|
Build Size ReportChanges to minified artifacts in 3 files changedTotal change +231 B View Changes
|
Build Size ReportChanges to minified artifacts in 5 files changedTotal change +241 B View Changes
|
Build Size ReportChanges to minified artifacts in 5 files changedTotal change +207 B View Changes
|
We can't use negative lookahead until v12 though because it's a breaking change. And I don't have a timetable on that yet. |
@joshgoebel This is an adapted version of Javascript's implementation which is already using negative lookahead ( see here). My understanding was that only lookbehind is not allowed currently. |
58079a4
to
a0db36f
Compare
Build Size ReportChanges to minified artifacts in 5 files changedTotal change +207 B View Changes
|
@joshgoebel Is there a way forward for this PR? If the concern is a language-specific breaking change, the Swift language itself is already using negative lookahead as well, here. |
Sorry for delay. I think debug_it("hello world") # debug_it is `title.function` (seems to be global function call)
person.eat("sandwich") # `eat` is a property of person, that also appears to be a method/function Thoughts? |
const KEYWORD_GUARD = { | ||
// Consume .keyword to prevent highlighting properties and methods as keywords. | ||
match: concat(/\./, either(...Swift.keywords)), | ||
const KEYWORD_PROP_GUARD = { |
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.
Ok, so we don't want the keyword engine to grab these as keywords, true, but if they are essentially "properly access" why wouldnt we scope them as that?
{ | ||
// Functions and macro calls | ||
scope: "title.function", | ||
keywords: KEYWORDS, |
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.
This seems weird, why would we have keywords popping up in the middle of a function name? Or is this truly to cover "it's a function name that's also a keyword"?
TRAILING_PAREN_REGEX, | ||
], | ||
scope: { | ||
2: "title.function", |
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.
We'd call anything that appears to be an object property access a property
for consistent highlighting across different grammars.
* @param {RegExp | string } re | ||
* @returns {string} | ||
*/ | ||
export function negativeLookahead(re) { |
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.
Awesome.
Improve fidelity by highlighting function calls in addition to definitions. This is already done by javascript, for example.
Changes
negativeLookahead
helper tolib/regex
title.function
(e.g.myFunction()
,obj.myFunction()
).title.function
(e.g.#myMacro()
).TRAILING_PAREN_REGEX
obj.if()
). Highlight keyword method calls also.#
and@
respectively. If they don't start with these, they're no longer considered reserved.`myFunc`()
). This feature exists so that reserved words can be used as identifiers.obj.myVariable
) remain unhighlighted for now.Next Steps (for a future PR)
exampleCall { print("action") }
Checklist
CHANGES.md