Skip to content

VimScript & Plugin Notes #7

@coolaj86

Description

@coolaj86

Just putting these somewhere so I don't lose them.

vimscript 101

' string
['a', 'b'] list
{ 'key': 'value' } map
" comment
\ escape previous newline+whitespace
# filepath
TitleCase function name

How to add a fixer?

DO NOT use hyphens in the file name!! ajscript_fmt.vim vs ajscript-fmt.vim

See https://github.com/dense-analysis/ale/pull/4427/files

autoload/ale/fix/registry.vim

# ale#fix#registry#Add(name, func, filetypes, desc, ...)
ale#fix#registry#Add(
\  'ajscript-fmt',
\  'ale#fixers#ajscript_fmt#Fix',
\  ['javascript', 'ajscript'],
\  'Apply AJScript format to a file.'
\)
\   'ajscript-fmt': {
\       'function': 'ale#fixers#ajscript_fmt#Fix',
\       'suggested_filetypes': ['javascript', 'ajscript'],
\       'description': 'Apply AJScript format to a file.',
\   },
    " g: global var
    " a: function argument
    " b: ?? variable
    " l: function-local variable
    " %t means current filename (says gpt)
    " :h means dirname (head)
    " :t means filename (tail)
function! ale#fixers#ajscript_fmt#GetCwd(buffer) abort
    let l:config = ale#path#FindNearestFile(a:buffer, '.ajscript.json')

    " Fall back to the directory of the buffer
    return !empty(l:config) ? fnamemodify(l:config, ':h') : '%s:h'
endfunction

LSP Server

https://www.toptal.com/javascript/language-server-protocol-tutorial

  call ale#linter#Define('filetype_here', {
  \   'name': 'any_name_you_want',
  \   'lsp': 'socket',
  \   'address': 'servername:1234',
  \   'project_root': '/path/to/root_of_project',
  \})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions