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

Implement Goto Definition Filters #3100

Open
ismell opened this issue Nov 22, 2019 · 0 comments
Open

Implement Goto Definition Filters #3100

ismell opened this issue Nov 22, 2019 · 0 comments

Comments

@ismell
Copy link

ismell commented Nov 22, 2019

Now that we are getting better syntax definitions and to make sublimehq/Packages#1861 a reality, I think we need to have the ability to filter the Goto Definition list.

Using the C syntax definition below

/* SYNTAX TEST "Packages/C++/C.sublime-syntax" */

struct device {
/*     ^^^^^^ meta.struct.c entity.name.struct.c */
  unsigned int address;
/*             ^^^^^^^ entity.name.member.c */
};

struct xhci {
/*     ^^^^ meta.struct.c entity.name.struct.c */
  struct device device;
/*       ^^^^^^ support.type.c */
/*              ^^^^^^ entity.name.member.c */
  unsigned int ports;
/*             ^^^^^ entity.name.member.c */
};

struct sdhci {
/*     ^^^^^ meta.struct.c entity.name.struct.c */
  struct device device;
/*       ^^^^^^ support.type.c */
/*              ^^^^^^ entity.name.member.c */
  unsigned int ports;
/*             ^^^^^ entity.name.member.c */
};

struct xhci xhci;
/*     ^^^^ support.type.c */
/*          ^^^^ entity.name.variable.global.c */

int main(void) {
  struct device *device = &xhci.device;
/*       ^^^^^^ support.type.c */
/*               ^^^^^^ entity.name.variable.local.c */
/*                         ^^^^ variable.other.c */
/*                              ^^^^^^ variable.other.member.c */

  device->address = 0x100;
/*^^^^^^ variable.other.c */
/*        ^^^^^^^ variable.other.member.c */

  return 0;
}

The scopes are targeted enough that we should be able to make Goto Definition pretty accurate by applying a scope filter to the definition list depending on the scope of the source.

Source Filter
support.type.c entity.name - entity.name.member - entity.name.variable
variable.other.c entity.name.variable
variable.other.member.c entity.name.member

In the case that no match is found with the filters applied, the original behavior of not having a filter should be used. This way if you have a struct name in a comment or string it will still allow you to navigate, but with more noise.

Today, if I push Goto Definition while my cursor is on device of support.type.c, it will return three entries, the declaration and the two members. This makes the list very noisy when dealing with a very large code base (i.e., Linux Kernel).

An added bonus would be to have some kind of filter so when you do Goto Definition on device of variable.other.c It only shows the entity.name.variable.local within the same meta.function.c. This way you don't get local variables for other functions. The C syntax definition does not currently label local variables as entity.name.variable.local to avoid all the noise.

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

No branches or pull requests

1 participant