Skip to content

Commit 648e385

Browse files
committed
fix: Match C source highlighting to VSCode
The theme was missing quite a few things to make it match VSCode.
1 parent 734ac03 commit 648e385

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ require("onedarkpro").setup({
129129
virtual_text = "NONE", -- Style that is applied to virtual text
130130
},
131131
filetypes = { -- Override which filetype highlight groups are loaded
132+
c = true,
132133
comment = true,
133134
go = true,
134135
html = true,
@@ -138,6 +139,7 @@ require("onedarkpro").setup({
138139
lua = true,
139140
markdown = true,
140141
php = true,
142+
printf = true,
141143
python = true,
142144
ruby = true,
143145
rust = true,

examples/c.c

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdbool.h>
2+
#include <stddef.h>
3+
#include <stdint.h>
4+
#include <stdio.h>
5+
6+
#define HELLO_WORLD "hello world"
7+
8+
#define LOG(...) printf(__VA_ARGS__)
9+
10+
typedef int myint_t;
11+
12+
struct hello {
13+
const char *world;
14+
uint64_t fd;
15+
struct hello *ptr;
16+
};
17+
18+
/*
19+
* Hello world
20+
*/
21+
int
22+
main(int argc, const char **argv)
23+
{
24+
// Hello world
25+
static const int rc = 0;
26+
27+
hello:
28+
printf("%s: %p", HELLO_WORLD, NULL);
29+
if (true) {
30+
return rc;
31+
} else {
32+
return 1;
33+
}
34+
35+
goto hello;
36+
}

lua/onedarkpro/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ local defaults = {
2626
virtual_text = "NONE", -- Style that is applied to virtual text
2727
},
2828
filetypes = { -- Enable/disable specific plugins
29+
c = true,
2930
comment = true,
3031
go = true,
3132
html = true,
@@ -35,6 +36,7 @@ local defaults = {
3536
lua = true,
3637
markdown = true,
3738
php = true,
39+
printf = true,
3840
python = true,
3941
ruby = true,
4042
rust = true,
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local M = {}
2+
3+
---Get the highlight groups for the filetype
4+
---@param theme table
5+
---@return table
6+
function M.groups(theme)
7+
local config = require("onedarkpro.config").config
8+
9+
return {
10+
["@constant.c"] = { fg = theme.palette.yellow },
11+
["@constant.builtin.c"] = { fg = theme.palette.yellow },
12+
["@function.builtin.c"] = { fg = theme.palette.cyan },
13+
["@label.c"] = { fg = theme.palette.red },
14+
["@type.builtin.c"] = { fg = theme.palette.purple },
15+
["@type.qualifier.c"] = { fg = theme.palette.purple },
16+
["@variable.parameter.c"] = { fg = theme.palette.red, style = config.styles.parameters },
17+
18+
-- LSP Semantic Tokens
19+
["@lsp.type.macro.c"] = { fg = theme.palette.orange, style = config.styles.constants },
20+
["@lsp.typemod.function.defaultLibrary.c"] = { fg = theme.palette.cyan, style = config.styles.functions },
21+
["@lsp.typemod.variable.readonly.c"] = { fg = theme.palette.yellow, style = config.styles.variable },
22+
}
23+
end
24+
25+
return M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local M = {}
2+
3+
---Get the highlight groups for the filetype
4+
---@param theme table
5+
---@return table
6+
function M.groups(theme)
7+
return {
8+
["@character.printf"] = { fg = theme.palette.orange },
9+
}
10+
end
11+
12+
return M

0 commit comments

Comments
 (0)