Skip to content

fix: use MarkupContent respecting client markdown capabilities for all LSP documentation fields#66

Open
Copilot wants to merge 5 commits intomainfrom
copilot/fix-lsp-documentation-rendering
Open

fix: use MarkupContent respecting client markdown capabilities for all LSP documentation fields#66
Copilot wants to merge 5 commits intomainfrom
copilot/fix-lsp-documentation-rendering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 13, 2026

LSP clients were receiving plain strings or unconditional markdown for some Documentation fields, causing markdown syntax to render as raw text on non-markdown clients, or markdown to be sent to clients that never declared support for it.

Root causes

  • Object completion items (TopLevelCompletions): Documentation = obj.Doc assigned a raw string? directly — the only completion path not already using MarkupContent.
  • Signature help parameter info (4 places in CgScriptLanguageTarget.Hover.cs): ParameterInformation.Documentation was using the string variant of SumType<string, MarkupContent>.
  • All completion and signature-help docs: Were hardcoding MarkupKind.Markdown without checking whether the client declared markdown support, unlike the existing HoverContent() which already respected hover.contentFormat.

Changes

  • CgScriptLanguageTarget.cs: Two new capability flags read during Initialize():
    • _clientSupportsMarkdownCompletion from completionItem.documentationFormat
    • _clientSupportsMarkdownSignature from signatureHelp.signatureInformation.documentationFormat
  • CgScriptLanguageTarget.Hover.cs:
    • Extracted shared StripMarkdown(string) static helper that removes inline code spans, bold, italic, and --- separators, producing clean readable plain text in all cases.
    • Added CompletionDoc(string) helper — returns MarkupKind.Markdown when the client declares it, otherwise strips inline markdown and returns MarkupKind.PlainText.
    • Added SignatureDoc(string) helper — same pattern for signature-help documentation.
    • All SignatureInformation and ParameterInformation docs now use SignatureDoc(). Constructor docs include obsolete-deprecation prefixes.
  • CgScriptLanguageTarget.Completion.cs: All completion item Documentation fields (methods, properties, functions, objects, enum constants) now use CompletionDoc(), including obsolete-deprecation prefixes where applicable.

Before / After

// Before — plain string, no markdown rendering in client
Documentation = obj.Doc,

// After — respects client capability, strips markdown syntax for non-markdown clients
Documentation = CompletionDoc(obj.Doc ?? string.Empty),

Tests

  • CompletionObjectTests.cs: Verifies PlainText (with stripped markdown) when no capability declared, Markdown when declared.
  • DocumentationFormatTests.cs: Comprehensive coverage across all documentation-bearing response types — function completions (single-variant, multi-variant with --- separator, "both" capability), member method completions, member property completions, and signature help for functions, methods, and constructors. Each scenario asserts both the Kind and that the content is readable (no raw markdown syntax in plain-text output; markdown syntax preserved in markdown output).

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…ields

Co-authored-by: hientrung <6129457+hientrung@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix formatting issue in LSP documentation fix: use MarkupContent with kind markdown for all LSP documentation fields Mar 13, 2026
Copilot AI requested a review from hientrung March 13, 2026 04:27
@hientrung hientrung marked this pull request as ready for review March 13, 2026 04:30
Copy link
Copy Markdown
Member

@davhdavh davhdavh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot We check for capabilities on client connect. Should only send markdown if client can read markdown

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot We check for capabilities on client connect. Should only send markdown if client can read markdown

Done in 6aa1ec0. Added two new capability flags read during Initialize():

  • _clientSupportsMarkdownCompletion from completionItem.documentationFormat
  • _clientSupportsMarkdownSignature from signatureHelp.signatureInformation.documentationFormat

Added CompletionDoc() and SignatureDoc() helpers (mirroring the existing HoverContent() pattern) that send MarkupKind.Markdown when the client declares it, and strip inline markdown syntax and fall back to MarkupKind.PlainText otherwise. All completion item docs and all signature-help docs now go through these helpers.

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:

  • www.antlr.org
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.201/MSBuild.dll /noautoresponse /nologo /nodemode:1 /nodeReuse:true /low:false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title fix: use MarkupContent with kind markdown for all LSP documentation fields fix: use MarkupContent respecting client markdown capabilities for all LSP documentation fields Mar 31, 2026
Copilot AI requested a review from davhdavh March 31, 2026 02:24
Copy link
Copy Markdown
Member

@davhdavh davhdavh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The unittest just covers when the client says it can handle markdown... The point is that if it says plaintext only, it should get plaintext, and if it says both, it should get markdown... for ALL places where this is relevant.
And it should obviously look nice in both cases... e.g. double newline in markdown is a just a section/paragraph change, but in plaintext is a double newline...

Copilot AI and others added 2 commits March 31, 2026 03:27
… doc helpers

Co-authored-by: davhdavh <1201165+davhdavh@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

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:

  • www.antlr.org
    • Triggering command: /usr/bin/dotnet dotnet test Catglobe.CgScript.EditorSupport.Lsp.Tests/ -p:Antlr4ToolPath=/home/REDACTED/.m2/antlr4-4.13.1-complete.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from davhdavh March 31, 2026 03:41
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

Successfully merging this pull request may close these issues.

3 participants