Skip to content

Commit

Permalink
feat: add proper support for javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Oct 2, 2020
1 parent ec88a48 commit 1f1a5b1
Show file tree
Hide file tree
Showing 15 changed files with 4,526 additions and 3,484 deletions.
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ RUN install_vim -tag neovim:v0.2.0 -py3 -build
RUN install_vim -tag neovim:v0.4.3 -py3 -build

# Install base dependencies.
RUN apk -v --progress add bash git
RUN apk -v --progress add clang=8.0.0-r0
RUN apk -v --progress add --no-cache bash git

# Install addition python modules.
RUN pip3 install --upgrade pip vim-vint==0.3.15 clang setuptools
# Install NodeJS.
RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community nodejs nodejs-npm
RUN npm install -g node-gyp

ENV NODE_PATH="/usr/lib/node_modules"
RUN npm -g config set user root
RUN npm install -g tree-sitter tree-sitter-typescript

# Create a symlink to our libclang binary.
RUN ln -s /usr/lib/libclang.so.8 /usr/lib/libclang.so
# Install addition python modules.
RUN pip3 install --upgrade pip vim-vint==0.3.15 setuptools

# Cleanup.
RUN rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
Expand Down
10 changes: 9 additions & 1 deletion autoload/doge/helpers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ endfunction
function! doge#helpers#parser(args) abort
let l:parser = g:doge_dir . '/parsers/' . b:doge_parser . '.js'
if filereadable(l:parser) != v:false
let l:args = [expand('%:p'), line('.')] + a:args
let l:cursor_pos = getpos('.')
let l:current_line = l:cursor_pos[1]
let l:tempfile = tempname()
call execute('%!tee ' . l:tempfile, 'silent!')
let l:args = [l:tempfile, l:current_line] + a:args
let l:result = system('node ' . l:parser . ' ' . join(l:args, ' '))

try
return json_decode(l:result)
catch /.*/
echo '[DoGe] ' . b:doge_parser . ' parser failed'
echo l:result
finally
call setpos('.', l:cursor_pos)
call delete(l:tempfile)
endtry
endif
return 0
Expand Down
1 change: 1 addition & 0 deletions autoload/doge/pattern.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function! doge#pattern#generate(pattern) abort
\ l:param,
\ a:pattern['parameters']['format']
\ )

if type(l:format) == v:t_list
call add(l:formatted_params, join(l:format, "\n"))
else
Expand Down
5 changes: 1 addition & 4 deletions autoload/doge/token.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function! s:token_replace(tokens, text) abort
" - {name|default}
" so if the line contains a pipe character with a default value then we
" grab that value and remove it from the text.
let l:stripped_token = matchlist(l:text, '\m{\([^|{}]\+\)\%(|\([^}]*\)\)\?}')
let l:stripped_token = matchlist(l:text, '\m{\(' . l:token . '\)\%(|\([^}]*\)\)\?}')
let l:token_default_value = doge#helpers#trim(get(l:stripped_token, 2, ''))
let l:has_token_default_value = !empty(l:token_default_value)

Expand Down Expand Up @@ -102,9 +102,6 @@ function! s:token_replace(tokens, text) abort
" Replace the <Bar> back to a pipe character.
let l:text = substitute(l:text, '\m<Bar>', '|', 'g')

" For JSDoc we replace the type hints 'typeA | type B' with 'typeA|typeB'.
let l:text = substitute(l:text, '\m\s*|\s*', '|', 'g')

" Empty lines will be added to the empty in the doge#pattern#generate()
" function and to indicate it should be prevented from rendering we have to
" add some kind of format. We use a dash '-' as an indication that it should
Expand Down
31 changes: 24 additions & 7 deletions ftplugin/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let b:doge_patterns = doge#buffer#get_patterns()

" let s:object_functions_pattern = doge#helpers#deepextend(s:pattern_base, {
" \ 'match': '\m^[[:punct:]]\?\([[:alnum:]_-]\+\)[[:punct:]]\?\s*:\s*\(async\)\?\s*\%(function\)\?\s*\%([[:alnum:]_]\+\)\?(\(.\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\%(\s*=>\s*\)\?\s*[({]',
" \ 'tokens': ['funcName', 'async', 'parameters', 'return_type'],
" \ 'tokens': ['funcName', 'async', 'parameters', 'returnType'],
" \})

" let s:class_pattern = doge#helpers#deepextend(s:pattern_base, {
Expand All @@ -29,17 +29,17 @@ let b:doge_patterns = doge#buffer#get_patterns()

" let s:function_pattern = doge#helpers#deepextend(s:pattern_base, {
" \ 'match': '\m^\%(\%(export\|export\s\+default\|public\|private\|protected\)\s\+\)*\(static\s\+\)\?\(async\s\+\)\?\%(function\(\*\)\?\s*\)\?\%([[:alnum:]_$]\+\)\?\s*\%(<[[:alnum:][:space:]_,=]*>\)\?\s*(\s*\(\%(\%(@[[:alnum:]_]\+(\s*.\{-})\)\s\+\)\?.\{-}\)\s*)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>&]\+\))\?\)\?\s*[{(]',
" \ 'tokens': ['static', 'async', 'generator', 'parameters', 'return_type'],
" \ 'tokens': ['static', 'async', 'generator', 'parameters', 'returnType'],
" \})

" let s:prototype_pattern = doge#helpers#deepextend(s:pattern_base, {
" \ 'match': '\m^\([[:alnum:]_$]\+\)\.prototype\.\([[:alnum:]_$]\+\)\s*=\s*\(async\s\+\)\?\%(function\(\*\)\?\s*\)\?({\?\([^>]\{-}\)}\?)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*\(=>\s*\)\?[{(]',
" \ 'tokens': ['className', 'funcName', 'async', 'generator', 'parameters', 'return_type'],
" \ 'tokens': ['className', 'funcName', 'async', 'generator', 'parameters', 'returnType'],
" \})

" let s:fat_arrow_function_pattern = doge#helpers#deepextend(s:pattern_base, {
" \ 'match': '\m^\%(\%(export\|export\s\+default\)\s\+\)\?\%(\%(\%(var\|const\|let\)\s\+\)\?\%(\(static\)\s\+\)\?\([[:alnum:]_$]\+\)\)\?\s*=\s*\(static\s\+\)\?\(async\s\+\)\?\%(function\(\*\)\?\s*\)\?\(({\?[^>]\{-}}\?)\|[[:alnum:]_$]\+\)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*\%(=>\s*\)\?[^ ]\{-}',
" \ 'tokens': ['static', 'funcName', 'static', 'async', 'generator', 'parameters', 'return_type'],
" \ 'tokens': ['static', 'funcName', 'static', 'async', 'generator', 'parameters', 'returnType'],
" \})

" ==============================================================================
Expand All @@ -50,7 +50,7 @@ let b:doge_patterns = doge#buffer#get_patterns()

call doge#buffer#register_doc_standard('jsdoc', [
\ {
\ 'node_types': ['class_declaration'],
\ 'node_types': ['class_declaration', 'class'],
\ 'template': [
\ '/**',
\ ' * !description',
Expand All @@ -60,9 +60,26 @@ call doge#buffer#register_doc_standard('jsdoc', [
\ ],
\ },
\ {
\ 'node_types': ['member_expression'],
\ 'parameters': {
\ 'format': '@param {{type|!type}} %(default|[)%{name|!name}%(default|])% - !description',
\ },
\ 'template': [
\ '/**',
\ ' * !description',
\ ' *',
\ ' * @function {functionName}#{propertyName}',
\ '%(async| * @async)%',
\ '%(generator| * @generator)%',
\ '%(parameters| * {parameters})%',
\ '%(returnType| * @return {{returnType|!type}} !description)%',
\ ' */',
\ ],
\ },
\ {
\ 'node_types': ['arrow_function', 'function', 'function_declaration', 'method_definition', 'generator_function_declaration'],
\ 'parameters': {
\ 'format': '@param {{type|!type}} %(default|[)%{name}%(default|])% - !description',
\ 'format': '@param {{type|!type}} %(default|[)%{name|!name}%(default|])% - !description',
\ },
\ 'template': [
\ '/**',
Expand All @@ -72,7 +89,7 @@ call doge#buffer#register_doc_standard('jsdoc', [
\ '%(async| * @async)%',
\ '%(generator| * @generator)%',
\ '%(parameters| * {parameters})%',
\ '%(return_type| * @return {{return_type|!type}} !description)%',
\ '%(returnType| * @return {{returnType|!type}} !description)%',
\ ' */',
\ ],
\ },
Expand Down
183 changes: 0 additions & 183 deletions generators/libclang.py

This file was deleted.

Loading

0 comments on commit 1f1a5b1

Please sign in to comment.