-
Notifications
You must be signed in to change notification settings - Fork 46
feat(razor): razor cohosting support #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
seblyng
reviewed
Nov 27, 2025
- 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.
seblyng
approved these changes
Nov 28, 2025
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
tris203
commented
Dec 1, 2025
- 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.
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.
seblyng
reviewed
Dec 4, 2025
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.
seblyng
approved these changes
Dec 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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