Skip to content

Semantic token localScope/globalScope/fileScope/classScope modifiers #2152

Open
@lf-

Description

@lf-

I would like to have the standard support scope modifiers for tokens. We're considering possibly implementing these at static-ls at work, but the lack of standardization makes it so that we probably will implement "is exported" as a code lens instead initially as most engineers won't have editors that display them.

It seems like this is a pretty broadly applicable concern: whether something is exported public API or internal API. Go considers this so important as to reserve first-character casing for communicating this information, but LSP currently doesn't have a standard way to offer it on other languages.

Prior art: https://clangd.llvm.org/features#modifiers

Clangd uses these like so:

  • fileScope: static void foo(void) has call and definition sites of foo annotated as fileScope
  • globalScope: write(2, "meow", 4) has write as globalScope and defaultLibrary. Similarly for a void bar(void); in the same file since it is exported.
  • classScope: idk, probably member variables. This functionality is really important since this is a confusing part of C++.
  • functionScope: variables which are just inside one function, e.g. int j;

I will note that in my role as a Haskell programmer classScope is not useful to us as we don't have objects with scope that behaves like C++/Java classes, but many languages have an idea of classes and it would be useful for those. I also don't know how e.g. OCaml modules should handle module-local variables. Should "is in scope because of the current module" be a modifier? Should those be "global scope" regardless?

What about nested Python functions?

IMO the most important of these to get standardized is whether something is an export (globalScope) or file-scope only, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions