Skip to content

Commit b6d5d59

Browse files
committed
neovim config hints
1 parent dc3d391 commit b6d5d59

File tree

8 files changed

+120
-8
lines changed

8 files changed

+120
-8
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ mipsy/
88
target/
99
syntaxes/
1010
lsp_data.json
11-
vim-out/

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ The inclusion of `a.s` in the above line is optional, but makes it easy to copy
6565

6666
If you're using a build of code without the proprietary marketplace, you can either grab a release from the Github releases (it might be out of date, let me know if that's the case), download the VSIX for the [extension page](https://marketplace.visualstudio.com/items?itemName=xavc.xavc-mipsy-features), or build the extension yourself.
6767

68-
I've got the language server working somewhat smoothly in neovim. If you're interested in more details let me know and I'll write up some more specific instructions. The language server should work for [any editor which supports the language server protocol](https://microsoft.github.io/language-server-protocol/implementors/tools/). The debugger uses the debug adapter protocol, which means that the basic features of the debugger should theoretically work with other editors, but I haven't tested that yet.
68+
I've got the language server working somewhat smoothly in neovim, see below. The language server should work for [any editor which supports the language server protocol](https://microsoft.github.io/language-server-protocol/implementors/tools/). The debugger uses the debug adapter protocol, which means that the basic features of the debugger should theoretically work with other editors, but I haven't tested that yet.
69+
70+
## Neovim
71+
72+
A bit of manual config is required (this is far from ergonomic), but these steps work for me:
73+
1. Either build this repo (see [Build](#build)), or grab a built copy by unzipping the published VSIX.
74+
2. Copy/symlink `vim-out/mipsy.lua` into `~/.config/nvim/lua/mipsy.lua`, and adjust the path to the `mipsy-lsp.sh` script in the LSP setup part of `mipsy.lua` to the correct location. Or add `vim-out` to your PATH and just replace the line with `cmd = { 'mipsy-lsp.sh' }`.
75+
3. Copy/symlink `vim-out/mips.vim` into where you put your syntax files, e.g. `~/.config/nvim/syntax/mips.vim`. You may want to edit the syntax file to your taste.
76+
4. Make sure to `require('mipsy').setup()` and then call `lspconfig.mipsy_editor_features.setup(...)` in your startup lua config.
77+
78+
Some tweaking and debugging is probably required.
6979

7080
# Technical details
7181

generate_syntax.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ def read_instructions(key):
289289
for directive in DIRECTIVES:
290290
vimscript_syntax.append(f'syn match Type "\\.{directive}"')
291291

292-
vimscript_syntax.append(f'syn match Identifier "{PARSE_IDENT}"')
293-
vimscript_syntax.append(f'syn match Label "{PARSE_IDENT}[ \\t]:"')
292+
# vimscript_syntax.append(f'syn match Identifier "{PARSE_IDENT}"')
293+
vimscript_syntax.append(f'syn match Function "{PARSE_IDENT}"')
294+
vimscript_syntax.append(f'syn match Label "{PARSE_IDENT}[ \\t]*:"')
294295
vimscript_syntax.append(f'syn match Comment "#.*$"')
295296

296297
vimscript_syntax.append(r'syn region asmString start="\"" end="\"" skip="\\\\\|\\\""')
@@ -320,11 +321,12 @@ def vim_escape(s):
320321
)
321322

322323
vimscript_syntax.extend([
324+
'hi def link asmString String',
323325
'', '',
324326
'let b:current_syntax = "mips"',
325327
'let &cpo = s:cpo_save',
326328
'unlet s:cpo_save',
327329
])
328330

329331
with open(os.path.join('vim-out', 'mips.vim'), 'w', newline='\n') as mips_syntax_file:
330-
mips_syntax_file.write('\n'.join(vimscript_syntax))
332+
print('\n'.join(vimscript_syntax), file=mips_syntax_file)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Mipsy Editor Features",
44
"description": "",
55
"publisher": "xavc",
6-
"version": "1.1.2",
6+
"version": "1.3.0",
77
"repository": {
88
"url": "https://github.com/XavierCooney/mipsy-editor-features"
99
},

vim-out/mips.vim

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
if exists("b:current_syntax")
2+
finish
3+
endif
4+
let s:cpo_save = &cpo
5+
set cpo&vim
6+
syn case ignore
7+
8+
9+
syn match Type "\.text"
10+
syn match Type "\.data"
11+
syn match Type "\.ktext"
12+
syn match Type "\.kdata"
13+
syn match Type "\.ascii"
14+
syn match Type "\.asciiz"
15+
syn match Type "\.byte"
16+
syn match Type "\.half"
17+
syn match Type "\.word"
18+
syn match Type "\.float"
19+
syn match Type "\.double"
20+
syn match Type "\.space"
21+
syn match Type "\.align"
22+
syn match Type "\.globl"
23+
syn match Function "[A-Za-z_][A-Za-z_0-9.]*"
24+
syn match Label "[A-Za-z_][A-Za-z_0-9.]*[ \t]*:"
25+
syn match Comment "#.*$"
26+
syn region asmString start="\"" end="\"" skip="\\\\\|\\\""
27+
syn match Number "\(-\?\)\(\(0x\)\([0-9a-fA-F]\+\)\|\(0b\)\([0-1]\+\)\|\(0o\?\)\([0-7]\+\)\|\([1-9][0-9]*\|0\)\)"
28+
syn match Identifier "\$zero"
29+
syn match Identifier "\$at"
30+
syn match Identifier "\$v0"
31+
syn match Identifier "\$v1"
32+
syn match Identifier "\$a0"
33+
syn match Identifier "\$a1"
34+
syn match Identifier "\$a2"
35+
syn match Identifier "\$a3"
36+
syn match Identifier "\$t0"
37+
syn match Identifier "\$t1"
38+
syn match Identifier "\$t2"
39+
syn match Identifier "\$t3"
40+
syn match Identifier "\$t4"
41+
syn match Identifier "\$t5"
42+
syn match Identifier "\$t6"
43+
syn match Identifier "\$t7"
44+
syn match Identifier "\$s0"
45+
syn match Identifier "\$s1"
46+
syn match Identifier "\$s2"
47+
syn match Identifier "\$s3"
48+
syn match Identifier "\$s4"
49+
syn match Identifier "\$s5"
50+
syn match Identifier "\$s6"
51+
syn match Identifier "\$s7"
52+
syn match Identifier "\$t8"
53+
syn match Identifier "\$t9"
54+
syn match Identifier "\$k0"
55+
syn match Identifier "\$k1"
56+
syn match Identifier "\$gp"
57+
syn match Identifier "\$sp"
58+
syn match Identifier "\$fp"
59+
syn match Identifier "\$ra"
60+
hi def link asmString String
61+
62+
63+
let b:current_syntax = "mips"
64+
let &cpo = s:cpo_save
65+
unlet s:cpo_save

vim-out/mipsy-lsp.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
cd "$(dirname "$(realpath $0)")"/..
4+
node ./out/server.js --stdio

vim-out/mipsy.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
return {
2+
setup = function()
3+
-- register the 'mips' filetype (use pattern to have higher
4+
-- priority over native asm filetype)
5+
vim.filetype.add({
6+
pattern = { ['.*%.s'] = { 'mips', { priority = 10 } } }
7+
})
8+
9+
-- make a custom lspconfig
10+
local lspconfig = require('lspconfig')
11+
require('lspconfig.configs').mipsy_editor_features = {
12+
default_config = {
13+
cmd = { vim.fn.expand('~/src/mipsy-editor-features/vim-out/mipsy-lsp.sh') },
14+
filetypes = { 'mips' },
15+
root_dir = lspconfig.util.root_pattern('*.s'),
16+
single_file_support = true,
17+
settings = {},
18+
};
19+
}
20+
21+
-- indentation config
22+
local indentGroup = vim.api.nvim_create_augroup("MipsIndentation", { clear = true })
23+
vim.api.nvim_create_autocmd(
24+
{ 'FileType' },
25+
{
26+
pattern = 'mips',
27+
command = 'setlocal shiftwidth=8 tabstop=8 noexpandtab',
28+
group = indentGroup
29+
}
30+
)
31+
end
32+
}

0 commit comments

Comments
 (0)