Warn and quick-fix inline comments in .editorconfig#476
Warn and quick-fix inline comments in .editorconfig#476
Conversation
Agent-Logs-Url: https://github.com/editorconfig/editorconfig-vscode/sessions/0ba1c3b3-2b48-484d-99c0-c01ea49526c9 Co-authored-by: SunsetTechuila <115353812+SunsetTechuila@users.noreply.github.com>
|
@copilot Inline comments are red, but how do we show an actual error? Is LSP required for this? |
Agent-Logs-Url: https://github.com/editorconfig/editorconfig-vscode/sessions/3abe6736-ac54-4860-9162-9ef9f3c0af05 Co-authored-by: SunsetTechuila <115353812+SunsetTechuila@users.noreply.github.com>
Agent-Logs-Url: https://github.com/editorconfig/editorconfig-vscode/sessions/3abe6736-ac54-4860-9162-9ef9f3c0af05 Co-authored-by: SunsetTechuila <115353812+SunsetTechuila@users.noreply.github.com>
No LSP needed. Added
The |
| * Lines where `#` or `;` is the first non-whitespace character are proper | ||
| * standalone comments and are excluded before this regex is applied. | ||
| */ | ||
| const INLINE_COMMENT_RE = /\S.*[ \t]+([#;].*)$/ |
There was a problem hiding this comment.
@copilot Do we need to use a regex here? Can't we use invalid.illegal.inline-comment.editorconfig?
There was a problem hiding this comment.
Unfortunately no — VS Code's extension API doesn't expose TextMate grammar token scopes at runtime. The invalid.illegal.inline-comment.editorconfig scope lives entirely inside VS Code's syntax highlighting engine and there's no public API to query what scope a given document position has. So the detection logic must be reimplemented in TypeScript.
I've added a comment (commit 9efd460) directly above the regex to explain this and cross-reference the grammar rule, so it's clear the two are intentionally in sync.
…provider Agent-Logs-Url: https://github.com/editorconfig/editorconfig-vscode/sessions/4832367c-d136-4899-946a-39e1d7d3fa6c Co-authored-by: SunsetTechuila <115353812+SunsetTechuila@users.noreply.github.com>
|
@copilot This feels hacky. How does language support work in VSCode in general? How do other language extensions handle syntax errors? |
In VS Code, language support is usually split like this:
Other extensions normally report syntax errors from a parser/validator, not from TextMate scopes. TextMate grammars are mainly for tokenization/highlighting, and VS Code doesn’t expose those scopes back to extensions as a diagnostics API. So for a small format like
I chose (1) because it keeps the implementation small and matches the rest of this extension’s architecture. If you’d prefer, I can rework it toward a parser-backed validator instead of the current regex-based warning path. |
|
We need an LSP |
|
@copilot How do error auto-fixes work in VSCode?
Can you implement one that moves inline comments to a new line? |
Agent-Logs-Url: https://github.com/editorconfig/editorconfig-vscode/sessions/91a5eba2-d906-43ed-bec4-f340a988909c Co-authored-by: SunsetTechuila <115353812+SunsetTechuila@users.noreply.github.com>
Agent-Logs-Url: https://github.com/editorconfig/editorconfig-vscode/sessions/91a5eba2-d906-43ed-bec4-f340a988909c Co-authored-by: SunsetTechuila <115353812+SunsetTechuila@users.noreply.github.com>
Implemented in 8081120 via a standard VS Code
... Implemented in 8081120. VS Code auto-fixes are usually surfaced as code actions tied to diagnostics, and this now adds a Quick Fix titled indent_style = space
# requiredIt also preserves indentation for indented keys/comments and clears the warning after the edit. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Let's imagine we have an LSP. How do we integrate it into VSCode? Do we need any changes on the side of this extension? |
Yes — if we moved to an LSP, this extension would need client-side changes. Concretely, on the VS Code side we would typically:
What can stay as-is:
So the answer is: yes, this extension would need changes, but mostly around bootstrapping the client and deciding which current providers move behind the LSP versus remain local.
|
@copilot Don't be that concise. Provide more detailed info |
More detail: If we introduce an LSP, this repo becomes the VS Code client for that server. We would not replace the whole extension — we would keep the VS Code extension, but change what happens at activation time. Typical integration looks like this:
So yes, there are definitely extension-side changes. The minimum client work is roughly:
For this specific PR, the likely migration path would be:
What probably stays in the extension even with an LSP:
What changes architecturally is that the extension stops computing diagnostics itself and instead becomes the host that launches the server and forwards results into VS Code. VS Code then shows those server results in the same Problems / Quick Fix UI, so from the user’s perspective it feels native. In practice, the main risk is duplicate behavior during migration. If the extension keeps local diagnostics while the LSP also reports them, users will see duplicate squiggles/code actions. So we would want a clean ownership split: either local providers, or LSP-backed providers for a given feature. So the short version is: yes, this extension needs changes, but mostly client bootstrap/orchestration changes rather than rewriting the whole extension.
|


The EditorConfig spec does not support inline comments, but they were silently accepted, causing rules to silently break with no visual feedback. For example:
Changes
inlineCommentgrammar pattern (invalid.illegal.inline-comment.editorconfig) — renders inline#/;comments with a red tint via syntax highlightingsectionpatterns — flags inline comments after section headers (after])valuepatterns — flags inline comments after rule values (after=)EditorConfigDiagnosticsProvider— uses VS Code'slanguages.createDiagnosticCollectionAPI (no LSP required) to emitWarning-severity diagnostics for inline comments, producing yellow squiggly underlines and Problems panel entries with the message: "Inline comments are not supported in EditorConfig. Move this comment to its own line."EditorConfigCodeActionProviderquick fix — adds a standard VS Code Quick Fix action, "Move inline comment to its own line", that rewrites invalid lines likeindent_style = space #requiredinto:Valid line-starting comments (
# .../; ...) are unaffected; they are matched by the existingcommentpattern first and excluded from diagnostic analysis.