Skip to content

Commit

Permalink
feat: add roslyn support
Browse files Browse the repository at this point in the history
  • Loading branch information
seblj authored and xzbdmw committed Jan 5, 2025
1 parent 2fc2b9b commit 20253cd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua/colorful-menu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ M.config = {
-- Such as "From <stdio.h>".
extra_info_hl = "@comment",
},
roslyn = {
extra_info_hl = "@comment",
},
fallback = true,
},
fallback_highlight = "@variable",
Expand Down Expand Up @@ -186,6 +189,9 @@ function M.highlights(completion_item, ls)
elseif ls == "intelephense" then
item = require("colorful-menu.languages.php").intelephense(completion_item, ls)
--
elseif ls == "roslyn" then
item = require("colorful-menu.languages.cs").roslyn(completion_item, ls)
--
else
-- No languages detected so check if we should highlight with default or not
if not M.config.ls.fallback then
Expand Down
59 changes: 59 additions & 0 deletions lua/colorful-menu/languages/cs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
local utils = require("colorful-menu.utils")
local Kind = require("colorful-menu").Kind
local config = require("colorful-menu").config

local M = {}

---@param completion_item lsp.CompletionItem
---@param ls string
---@return CMHighlights
function M.roslyn(completion_item, ls)
local label = completion_item.label
local description = completion_item.labelDetails and completion_item.labelDetails.description
local kind = completion_item.kind

local text = label

if not kind then
return utils.highlight_range(text, ls, 0, #text)
end

local highlight_name
if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then
highlight_name = "@type"
elseif kind == Kind.Constructor then
highlight_name = "@type"
elseif kind == Kind.Constant then
highlight_name = "@constant"
elseif kind == Kind.Function or kind == Kind.Method then
highlight_name = "@function"
elseif kind == Kind.Property or kind == Kind.Field then
highlight_name = "@property"
elseif kind == Kind.Variable then
highlight_name = "@variable"
else
highlight_name = config.fallback_highlight
end

local highlights = {
{
highlight_name,
range = { 0, #label },
},
}

if description then
text = label .. " " .. description
table.insert(highlights, {
config.ls.roslyn.extra_info_hl,
range = { #label + 1, #text },
})
end

return {
text = text,
highlights = highlights,
}
end

return M

0 comments on commit 20253cd

Please sign in to comment.