Motorola 68000 family language server

June 28, 2024 ยท View on GitHub

example workflow npm version

Language Server Protocol implementation for Motorola 68000 family assembly, based on tree-sitter-m68k

Features

  • Auto-completion:
    • Instruction mnemonics
    • Assembler directives
    • Registers
    • Symbols
  • Code Linting
    • Parser errors
    • Processor support
  • Code Folding
  • Document Formatting
  • Document Highlights
  • Document Links
  • Document Symbols
  • Find References
  • Go to definition
  • Hover
    • Instruction/directive documentation
    • Symbol info
  • Multiple workspaces
  • Rename Symbols
  • Signature Help

Installation

Install the package via npm:

npm install --global m68k-lsp-server

Usage

Neovim

Configure using nvim-lspconfig

e.g.

require('lspconfig').m68k.setup{
  on_attach = on_attach,
  init_options = {
    includePaths = { '../include', '/home/myuser/includes' },
    format = {
      case = {
        instruction = 'upper'
      }
    }
  }
}

Emacs

See emacs-m68k

Standalone server

Start the server e.g.:

m68k-lsp-server --stdio

Configuration

The LSP client can configured using the following settings, either as initialization options, or as a .m68krc.json file in your workspace root, for project specific overrides.

Processors:

Lists the processor(s) that your code is targeted at. This controls completion suggestions and provides diagnostics.

{
  "processors": ["mc68030", "mc68881"]
}

Default: ["mc68000"]

Supported values: mc68000 ,mc68010 ,mc68020 ,mc68030 ,mc68040 ,mc68060 ,mc68881 ,mc68851 ,cpu32

Include Paths:

Additional paths to use to resolve include directives. This is equivalent to INCDIR in source. It should probably include anything you pass to vasm -I arguments. Can be absolute or relative.

{
  "includePaths": ["../include", "/home/myuser/includes"]
}

Default: []

vasm diagnostics:

The server can use vasm to provide diagnostic messages. When enabled it will assemble source files on save/open and display any errors or warnings.

The server will use a local vasmm68k_mot executable if one exists in your path or is configured in vasm.binPath, otherwise it will default to a bundled version complied in Web Assembly.

{
  "vasm": {
    "provideDiagnostics": true,
    "binPath": "vasmm68k_mot",
    "args": [],
    "preferWasm": false,
    "exclude": []
  }
}

(defaults)

PropertyDescription
provideDiagnosticsEnable vasm diagnostics
binPathFilename or full path of vasm executable binary
argsCustom arguments to pass to vasm. Include paths and processor(s) from server config will automatically be added
preferWasmAlways use bundled Web Assembly vasm
excludeFile patterns to ignore and not build directly e.g. ["*.i"]

Formatting:

The language server supports document formatting which can be configured using the following options:

Case

Enforce consistency of upper/lower case on elements which are normally case insensitive.

OptionBehaviour
upperUpper case
lowerLower case
anyDo not change case

This can either be configured globally for all elements:

{
  "format": {
    "case": "lower"
  }
}

or per element type

{
  "format": {
    "case": {
      "instruction": "lower",
      "directive": "lower",
      "control": "upper",
      "sectionType": "lower",
      "register": "lower",
      "hex": "lower"
    }
  }
}
ElementDescription
instructionInstruction mnemonic/size e.g. move.w
directiveAssembler directive mnemonic/qualifier e.g. include
controlAssembler control keywords e.g. ifeq/endc
sectionTypeSection type e.g. bss
registerRegister name e.g. d0,sr
hexHexadecimal number literal

Default: "lower"

Label colon

Determines whether labels should have a colon suffix.

Can be set for all labels:

{
  "format": {
    "labelColon": "on"
  }
}

or individually for global and local labels:

{
  "format": {
    "labelColon": {
      "global": "on",
      "local": "off"
    }
  }
}
OptionBehaviour
onAdd colon
offRemove colon
notInlineNo colon for labels on same line as instruction
onlyInlineOnly add colon for labels on same line as instruction
anyDo not change

Default: "on"

Operand space

Include space between operands e.g. move d0, d1. VASM needs -spaces or -phxass option to support this.

OptionBehaviour
onAdd space
offRemove space
anyDo not change

Default: "off"

{
  "format": {
    "operandSpace": "off"
  }
}

Quotes

Quote style to use for strings and paths.

{
  "format": {
    "quotes": "single"
  }
}
OptionBehaviour
singleSingle quotes: '
doubleDouble quotes: "
anyDo not change

Default: "double"

Align

Indents elements to align by type.

{
  "format": {
    "align": {
      "mnemonic": 8,
      "operands": 16,
      "comment": 48,
      "operator": 0,
      "value": 0,
      "indentStyle": "space",
      "tabSize": 8,
      "autoExtend": "line"
    }
  }
}

(defaults)

PropertyDescription
mnemonicPosition of instruction/directive mnemonic and size e.g. move.w,include.
operandsPosition of operands e.g. d0,d1.
commentPosition of comment following statement. Comments on their own line are not affected.
operatorPosition of = character in constant assignment
valuePosition of value in constant assignment
standaloneCommentPosition / behaviour of comment with no other elements on the same line.
indentStyleCharacter to use for indent - tab or space.
tabSizeWidth of tab character to calculate positions when using tab indent style.
autoExtendBehaviour when a component exceeds the available space between positions. See below.

Options for standaloneComment:

OptionBehaviour
"nearest"Align to nearest element position (default). E.g. if current position is closest to mnemonic it snaps to that column
"ignore"Don't align
elementNameAlign to named element position e.g. "label", "mnemonic", "operands"
numberNumeric literal position

Options for autoExtend:

OptionBehaviour
lineAdjust the position for the affected line only
blockAdjust the position, maintaining alignment for all lines within the same block i.e. code separated by two or more line breaks
fileAdjust the position, maintaining alignment for all lines in the source file

Trim whitespace

Remove trailing whitespace from lines?

{
  "format": {
    "trimWhitespace": true
  }
}

default: true

Final new line

Require line break on final line?

{
  "format": {
    "finalNewLine": true
  }
}

End-of-line character

New line type: lf, cr, crlf

{
  "format": {
    "endOfLine": "lf"
  }
}

default: lf

TODO

  • Full documentation for 68010+ instructions
  • Diagnostics
    • Instruction signatures
  • Amiga or other platform specific docs?

License

This project is made available under the MIT License.