madskristensen / EditorConfigLanguage

A Visual Studio extension
Other
128 stars 37 forks source link

Language service improvements around .NET naming rules #89

Open zspitz opened 3 years ago

zspitz commented 3 years ago

Installed product versions

Description

On top of the basic key = value syntax of .editorconfig, the .NET compilers (C#, VB.NET and perhaps others) can use .editorconfig files to enforce (or ignore) naming conventions for various code elements.

Conceptually, this system has three kinds of entities, depending on whether the key starts with dotnet_naming_style., dotnet_naming_symbols., or dotnet_naming_rule.:

Entities are defined by one or more properties in the following syntax:

<kind>.<title>.<propertyName> = <propertyValue>

where <kind> is one of the above values, <title> is the name of the entity, and <propertyName> and <propertyValue> are specific to each entity kind.

There are some really powerful opportunities for improving the language service here. Using the following sample:

[*.{cs,vb}]
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_static_fields.required_modifiers = static

dotnet_naming_style.underscored.capitalization = pascal_case
dotnet_naming_style.underscored.required_prefix = _

dotnet_naming_rule.private_fields_underscored.symbols = private_fields
dotnet_naming_rule.private_fields_underscored.style = underscored
dotnet_naming_rule.private_fields_underscored.severity = error

dotnet_naming_rule.private_static_fields_none.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_none.style = underscored
dotnet_naming_rule.private_static_fields_none.severity = none

dotnet_naming_rule.public_members_must_be_capitalized.symbols  = public_symbols

Intellisense

When typing this: Intellisense: Comments
dotnet_naming_symbols. private_fields
private_static_fields
public_symbols
The first two are used in actual symbol definitions.
public_symbols is used as the value for a naming rule symbols property.
dotnet_naming_rule.public_members_must_be_capitalized.symbols = Same as above
dotnet_naming_symbols.private_fields. applicable_kinds
applicable_accessibilities
required_modifiers
The properties available for symbol groups
dotnet_naming_symbols.private_fields.applicable_kinds = abstract
async
const
must_inherit
readonly
static
shared
The available values for this property

Symbol renaming

Invoking the Rename refactoring on an entity name should modify all uses of that name -- both the keys in property setters, and the values in the naming rule setters. For example, Rename refactoring the underscored in the value of the following line:

dotnet_naming_rule.private_fields_underscored.style = underscored

to under_scored, should result in the following other changes:

dotnet_naming_style.under_scored.capitalization = pascal_case
dotnet_naming_style.under_scored.required_prefix = _
dotnet_naming_rule.private_static_fields_none.style = under_scored

Question: should this affect only the current file, or .editorconfig files in the parent folders as well?

Find all references

Invoking "Find all references" on a specific name should return all property setters with that kind+name, as well as all the places it's used in the value of a property setter.

Hover

Hover over Displays Notes
capitalization Capitalization style for words within the symbol
local Symbols defined within a method
underscored .capitalization = pascal_case ([*.{cs,vb}])
.required_prefix = _ ([*.{cs,vb}])
1. Needs to handle multiple glob patterns.
2. The glob pattern should be visually different from the value

Navigation

"Go to definition" on a specific name should navigate to the first property setting with that kind+name. Alternatively, it should follow the same strategy VS does with C# partial classes -- it would automatically open the Find all references pane on that kind+name.

Validation

The last line in the sample should have a red squiggly underneath it, because there are no property setters matching the public_symbols symbol group.

Missing required properties should also be recognized as errors.

Duplicate keys should also be flagged as errors.

Current behavior

The language service doesn't surface any of these behaviors.

zspitz commented 2 years ago

ping @BhaaLseN re #13

BhaaLseN commented 2 years ago

Sounds like a familiar report :)

I have to admit though, since VS 2019 extended on the support for .editorconfig (and even brought a UI editor at some point), I haven't used this extension since VS 2017. I didn't even change the naming settings since I got them dialed in back when and just forgot about them.

Just for reference though: I checked with VS 2022, and editing an .editorconfig with the plain text thing provides some syntax completion, but it's more like "those are words i know" rather than "this word makes sense in this context". So there is still value in providing this sort of guidance for users looking to create their .editorconfig 👍