microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.28k stars 29.31k forks source link

Add various missing `SymbolKind`|`CompletionItemKind` construct types widely used in languages #228787

Open geekley opened 1 month ago

geekley commented 1 month ago

I suggest adding these enumeration values to SymbolKind and CompletionItemKind.

Motivations

Parameter

Parameters are not at all the same as variables. They are bound to arguments. This is a very basic concept widely used in pretty much every programming language.

This distinction is more widely used than existing distinctions which are already available such as Class|Struct|Interface. Also there is TypeParameter already (which is a more specific concept).

It's strange that the outline view can show local variables, but not parameters. Also, in a foo(bar: x) call, you can only have parameters before a : completion, so it should be distinct from variables.

Macro

Macros are used in several languages, and I think they're widespread enough that they should be included as a specific language construct type.

Everyone knows about C and C++, but they are also in languages with a preprocessor similar to C, such as GLSL and GDShader, and also in assembly languages.

The concept of macros is actually even more generic that just this. Macros can be designed in different ways according to the language (for example, syntactic macros VS text-substitution macros). So they're found even in languages unrelated to C, like Lisp, Scala, Rust, etc. See macro on Wikipedia for more info.

Label

Go-to labels can be found in several languages like C/C++, C#, Java, Javascript, etc. Their very purpose is to mark a position in code, so it makes sense that a language might want to add them to outline. They should also be a specific completion type.

Section

A generic concept of a "section" would be useful for various languages. E.g. in markup languages like markdown, this could represent a header. This is also useful in data languages like INI. Programming languages also often have this concept, e.g. in C# #region directives. This concept is useful for both outlines and completion.

Tag

It would be better to have a specific construct type for tags. Tags are special as they describe instances of the tag type. The tag instance itself is not necessarily uniquely named; using things like "field", "variable" or "constant" is not appropriate.

It's obviously useful for languages like HTML, XML and SVG, as well as any other with a similar concept. Might be also useful in CSS, as well as JSX and TSX. So it's useful for markup languages and data languages, and possibly even programming languages that deal with tags.

Element

Basically the same concept as a tag, but since this would be a much more generic term, I think it's better as a separate value. Languages may want the concept of an "element" or an "item", but not really define it like a tag.

I'm suggesting a separate value because we already have e.g. Package|Namespace|Module being apparently considered different enough that they should be separate.

Annotation

The concept of annotations/decorators is used widely across languages, even though it's implemented differently (sometimes as classes, sometimes they're more like keywords, or even functions). Thus I believe a specific type would be beneficial.

Directive

This is basically an "instruction" that specifies or modifies how the entire code (or a portion of it) is to be interpreted.

Its article in Wikipedia shows this concept is used in various languages. An example is compiler/preprocessor directives in C/C++ and C# such as #pragma, etc.

A different usage might be constructs like shader_type x; and render_mode y, z; in GDShader. Maybe these aren't the best examples, but the idea is that since the term "directive" is a bit generic, this construct type could be used for things not covered by the other types, i.e. construct types which are too language-specific. So I still think it's useful in not just completions, but outline too.

Rule

This would be mainly useful in styling languages like CSS. Used on rule blocks, such as the block assigning declarations to a set of selectors, or maybe in at-rules too.

Could also be useful for whichever languages use the concept of "rules" in code, e.g. some declarative language.

In CSS it's useful mostly for outlines, but I assume it might also be useful in completion (e.g. at-rules, or for other languages which might have the concept of a named "rule")?

SymbolKind.Keyword

It may be useful to have Keyword also in SymbolKind. Languages can sometimes have a construct that is very relevant for the code structure, but doesn't really fit the available types, yet you may still want to add the keyword itself to the outline as a go-to point in the code (e.g. if you can only use that keyword once in that scope, or if you can't have something particular like a unique identifier on the construct).

Related

63802

131163

2628

I think @jrieken may be interested in providing feedback?

vs-code-engineering[bot] commented 1 month ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vs-code-engineering[bot] commented 5 days ago

This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!