Highlight visibility method arguments and stop highlighting shadowing locals - #13
Open
tarebyte wants to merge 1 commit into
Open
Highlight visibility method arguments and stop highlighting shadowing locals#13tarebyte wants to merge 1 commit into
tarebyte wants to merge 1 commit into
Conversation
Follow-up to #8, which changed `private`, `protected` and `public` from `@keyword` to `@function.method.builtin` but only for the bare form. A bare `private` parses as an identifier, but `private :foo` and `private def bar; end` parse as calls and are claimed by the general call pattern, so they kept the ordinary `@function.method` capture. Add a call pattern after that one, using `!receiver` so an unrelated method with a colliding name stays an ordinary call. Guard the identifier pattern with `#is-not? local`, matching the general identifier pattern above it, so a local variable shadowing one of these names is highlighted as a variable rather than as a method call. That case was already wrong before #8, as a keyword. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac21705f-befb-4606-9c83-657e3e9ea0dc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #8. That PR moved
private,protectedandpublicoff@keyword, but it only covers the bare form. Two cases onmasterare still wrong.A local variable that shadows one of the names is highlighted as a method call. These names can be shadowed, which was part of #8's own argument for not treating them as keywords:
This was already wrong before #8 — it rendered as
keyword— so #8 changed which wrong capture it gets rather than fixing it.The argument forms do not get the built-in capture at all.
private :fooandprivate def bar; endparse as acall, which the general(call method: (identifier) @function.method)pattern claims. Later patterns win, so the identifier pattern added in #8 never applies to them:That leaves
privateandprivate :foorendering differently from each other.Change
#is-not? localto the identifier pattern. The query file already uses exactly this guard on the general@function.methodidentifier pattern a few lines above, so this follows the existing convention rather than introducing one.callpattern after the general call pattern, which is where therequirepattern already sits for the same precedence reason.!receiverkeeps an unrelated method that happens to share a name, such asacl.public, an ordinary call.Validation
332 corpus parses and 5 highlight files, zero failures.
test/highlight/classes.rbgoes from 14 to 19 assertions:private(bare)function.method.builtinprivate :with_symbolfunction.method.builtinprivate def with_def; endfunction.method.builtinprivate = 1then a bareprivatevariableacl.publicfunction.methodEach new assertion was confirmed to fail without its pattern. Removing
#is-not? localgivesexpected highlight 'variable', actual highlights: 'function.method.builtin'; removing the call pattern givesexpected highlight 'function.method.builtin', actual highlights: 'function.method'.