Skip to content

Conversation

@tris203
Copy link
Collaborator

@tris203 tris203 commented Nov 24, 2025

Summary Add Razor "cohosting" support so Razor files (.cshtml / .razor) can be handled together with the C# language server. This PR wires up the necessary cohosting handshake and routing so razor-language features (tag helpers, razor-specific diagnostics, completions) are available in projects that require a cohosted Razor service.

Closes #267

tris203 and others added 15 commits November 24, 2025 16:16
Introduce initial Razor LSP endpoint handlers in `handlers.lua` to support
server-to-client requests for HTML features (color, folding, hover, etc.).
Add type definitions for Razor HTML forwarded requests and logging in
`razor/types.lua`. Also add config for luacheck and Lua language server.
Refactor Razor types to replace multiple specific HtmlForwardedRequest
classes with a single generic HtmlForwardedRequest<T>. Update LSP
handler annotations to use the new generic type for improved clarity
and maintainability.
Introduce a document manager for Razor virtual HTML documents, including
`HtmlDocument` and `documentManager` modules. These handle creation,
updating, and retrieval of virtual HTML documents by URI and checksum.
Integrate the manager with the `razor/updateHtml` LSP handler to keep
the internal document store in sync with updates from the server.
- Change event emitter methods in roslyn_emitter.lua from colon (:) to dot (.)
  notation for consistency and clarity.
- Update get_code_actions return type to RoslynCodeAction[] for accuracy.
- Simplify SLN project line formatting in test helpers for readability.
- Disable max comment line length in .luacheckrc for flexibility.
- Implement `lspRequest` and `close` methods on HtmlDocument to allow
  forwarding LSP requests (e.g., hover) to the HTML language server.
- Update buffer creation and content management for HtmlDocument,
  ensuring buffers are created and updated as needed.
- Add support for closing and deleting buffers when documents are closed.
- Update hover handler to use the new forwarding mechanism.
- Improve type annotations and assertions for document lookup.
- Pass checksum to `lspRequest` in hover and formatting handlers.
- Update `lspRequest` to accept checksum and check for mismatches.
- Return nil or empty results on checksum mismatch or missing LSP client.
- Ensure correct result extraction from LSP sync requests.
Set the buffer type to 'nowrite' using an LspAttach autocmd instead of
immediately, ensuring the LSP client attaches properly to the buffer.
This avoids issues where setting 'nowrite' too early prevents LSP
attachment.
Moved content and checksum initialization out of HtmlDocument.new and into
the updateContent method. Now, the constructor only sets up the document's
basic structure, while content and checksum are managed separately. This
clarifies the responsibilities of each method and improves maintainability.
Refactored Razor document manager to use instance methods and improved
document lookup with checksum validation and pending update handling.
Replaced direct table access with helper functions and added warnings
for missing or mismatched documents. Updated LSP request logic to
remove redundant checksum checks and ensure proper client availability.
Move Razor-related LSP handlers from lsp/handlers.lua to a new
razor/handlers.lua module. Replace inline handler implementations with
references to the new module, reducing duplication and improving
maintainability. This change also standardizes the forwarding logic for
Razor HTML requests and logging.
Move the virtualHtmlSuffix constant to roslyn.razor.types and update all
references to use it. This improves maintainability and ensures
consistency across modules when handling virtual HTML document URIs.
Previously, the code incorrectly used colon syntax to access the
`emit` and `on` methods from the `roslyn_emitter` module, which is
not an object instance but a module table. This caused runtime errors
when attempting to emit or listen for events. This commit updates the
calls to use dot syntax, ensuring the methods are called correctly.
tris203 and others added 5 commits November 27, 2025 21:05
- Use `require("roslyn.razor.types").html_lsp_name` instead of hardcoded
  "html" for LSP client name, improving maintainability.
- Add `html_lsp_name` to types.lua for centralized configuration.
- Update autocmd in htmlDocument to only set `buftype` for the correct
  LSP client.
- Improve assertion messages for document not found cases.
- Change `virtualHtmlSuffix` to `__virtual.html` for clarity.
- Enhance handler to robustly extract URI from response or context.
Add an assertion to ensure the virtual HTML Document buffer is valid before
attempting to set its lines. This prevents errors when the buffer is no longer
valid, improving robustness when updating document content.
- Changed lspRequest call to use only res.request as parameter, removing
  ctx.params for clarity and correctness.
- Added type annotations for log and update_html handlers to improve
  code documentation and maintainability.
tris203 and others added 2 commits November 28, 2025 17:50
Although Roslyn supports prepareRename, cohosted Razor does not. This change
explicitly sets `renameProvider` to true in the server capabilities to ensure
rename functionality is available, even when prepareRename is not supported.
* Add razor filetype to .cshtml and .razor extensions
* Enable razor LSP cohosting setting
* Initiate roslyn when opening razor files
* Refresh diagnostics of razor files
* Configure roslyn to use the razor extension
- Disable semantic tokens for razor files on Neovim < 0.12 to avoid
  unsupported `/full` requests. This is a temporary workaround until
  Neovim 0.12 is stable.
- Refactor razor handler logging to use the internal log module and
  always log messages with their level, defaulting to "Unknown" if
  missing.
@tris203 tris203 marked this pull request as ready for review December 3, 2025 17:44
Clarify that Razor/CSHTML support is now included in this plugin,
superseding the old rzls.nvim. Advise users to uninstall rzls.nvim and
the rzls language server if previously used. Update binary information
to note inclusion of .razorExtensions for Razor/CSHTML support.
Update type hint for checksum parameter to optional in documentManager.
Replace deprecated vim.api.nvim_set_option_value with direct buffer option
assignment in htmlDocument for setting buftype. This modernizes code and
improves clarity.
@tris203 tris203 merged commit ab60e7e into seblyng:main Dec 4, 2025
2 checks passed
@tris203 tris203 deleted the cohosting branch December 4, 2025 15:16
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.

Razor Support

3 participants