Skip to content

Commit

Permalink
feat(highlights): add more hightlight groups
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Nov 4, 2024
1 parent ac11ed7 commit d964057
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 0 additions & 1 deletion lua/rzls/handlers/providesemantictokensrange.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ local empty_response = {}
---@param _ctx lsp.HandlerContext
---@param _config table
return function(_err, result, _ctx, _config)
vim.print("Called razor/provideSemanticTokensRange")
local vd = documentstore.get_virtual_document(
result.textDocument.uri,
result.requiredHostDocumentVersion,
Expand Down
11 changes: 10 additions & 1 deletion lua/rzls/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local handlers = require("rzls.handlers")
local documentstore = require("rzls.documentstore")
local razor = require("rzls.razor")

local M = {}

Expand Down Expand Up @@ -83,6 +84,7 @@ function M.setup(config)
end,
root_dir = root_dir,
on_attach = function(client, bufnr)
razor.apply_highlights()
documentstore.register_vbufs(bufnr)
rzlsconfig.on_attach(client, bufnr)
if not client.hacked_semantic then
Expand All @@ -108,7 +110,7 @@ function M.setup(config)
character = 0,
},
["end"] = {
line = vim.api.nvim_buf_line_count(tbufnr) - 1,
line = vim.api.nvim_buf_line_count(tbufnr),
character = (
string.len(vim.api.nvim_buf_get_lines(tbufnr, -2, -1, true)[1]) - 1
)
Expand Down Expand Up @@ -139,6 +141,13 @@ function M.setup(config)
end,
group = au,
})

vim.treesitter.language.register("html", { "razor" })

vim.api.nvim_create_autocmd("ColorScheme", {
group = au,
callback = razor.apply_highlights,
})
end

function M.load_existing_files(path)
Expand Down
22 changes: 22 additions & 0 deletions lua/rzls/razor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,26 @@ function M.map_to_document_ranges(lsp, bufnr, language_kind, ranges, cb)
}, cb)
end

---@type table<string, vim.api.keyset.highlight>
--TODO: Extend this to cover all razor highlights
-- https://github.com/dotnet/vscode-csharp/blob/802be7399e947ab82f2a69780d43a57c1d5be6aa/package.json#L4761
local razor_highlights = {
["@lsp.type.razorComment"] = { link = "Comment" },
["@lsp.type.razorCommentStar"] = { link = "Comment" },
["@lsp.type.razorCommentTransition"] = { link = "Comment" },
["@lsp.type.controlKeyword"] = { link = "Statement" },
["@lsp.type.punctuation"] = { link = "@punctuation.bracket" },
["@lsp.type.razorTransition"] = { link = "Keyword" },
["@lsp.type.razorDirective"] = { link = "Keyword" },
["@lsp.type.razorDirectiveAttribute"] = { link = "Keyword" },
["@lsp.type.field"] = { link = "@variable" },
["@lsp.type.variable.razor"] = { link = "@variable" },
}

M.apply_highlights = function()
for hl_group, hl in pairs(razor_highlights) do
vim.api.nvim_set_hl(0, hl_group, hl)
end
end

return M

0 comments on commit d964057

Please sign in to comment.