Skip to content

Commit

Permalink
fix: bugfix for deno supporting
Browse files Browse the repository at this point in the history
  • Loading branch information
jayli committed Feb 11, 2022
1 parent 529f549 commit f1e5ce8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 46 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ let g:easycomplete_tab_trigger="<c-space>"

By default you can use Tab to trigger the completion suggestions. Alse use Tab and Shift-Tab to select matched items. Use `Ctrl-]` for definition jumping, `Ctrl-t` for jumping back (Same as tags jumping). Or you can use `:EasyCompleteGotoDefinition` command.

Use `:EasyCompleteNextDiagnostic` and `:EasyCompletePreviousDiagnostic` for diagnostics jumping. For example, map diagnostic jumping to `<C-j>` and `<C-k>`:
Use `:EasyCompleteNextDiagnostic` and `:EasyCompletePreviousDiagnostic` for diagnostics jumping. The plugin has already map diagnostic jumping to `<C-j>` and `<C-k>`. You can change these mapping via:

```vim
nnoremap <silent> <C-j> :EasyCompleteNextDiagnostic<CR>
nnoremap <silent> <C-k> :EasyCompletePreviousDiagnostic<CR>
nnoremap <silent> <C-n> :EasyCompleteNextDiagnostic<CR>
nnoremap <silent> <C-p> :EasyCompletePreviousDiagnostic<CR>
```

In most cases, the plugin already map these tow HOTKEYs for you successfully. You only have to set custom diagnostic HOTKEYs manually in case of there was a conflict. By default press `<C-j>` or `<C-k>` for diagnostics jumping like this:
You only have to set custom diagnostic HOTKEYs manually in case of there was a conflict. By default press `<C-j>` or `<C-k>` for diagnostics jumping like this:

<img src="https://gw.alicdn.com/imgextra/i3/O1CN01veJhM51xTOxgC2bc7_!!6000000006444-2-tps-1090-118.png" width=550 />

Expand Down Expand Up @@ -89,6 +89,7 @@ All commands:
| `:EasyCompleteProfileStart` | Start record diagnostics message |
| `:EasyCompleteProfileStop` | Stop record diagnostics message |
| `:EasyCompleteLint` | Do diagnostic |
| `:DenoCache` | Do Deno Cache for downloading modules |

### Language Support

Expand Down Expand Up @@ -162,7 +163,7 @@ More info about semantic completion for each supported language:
- Yaml: [yaml-language-server](https://github.com/redhat-developer/yaml-language-server) required.
- Ruby: [solargraph](https://github.com/castwide/solargraph) required.
- Nim: [nimlsp](https://github.com/PMunch/nimlsp) required. [packages.json](https://github.com/nim-lang/packages/blob/master/packages.json) downloading is very slow, You'd better intall minlsp manually.
- Deno: [Deno](https://morioh.com/p/84a54d70a7fa) required.
- Deno: [Deno](https://morioh.com/p/84a54d70a7fa) required. Use `:DenoCache` command for `deno cache` current ts/js file.

#### Snippet Support

Expand Down
121 changes: 82 additions & 39 deletions autoload/easycomplete/sources/deno.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,57 @@ let g:easycomplete_sources_deno = 1
let s:file_extensions = ["js","jsx","ts","tsx","mjs","ejs"]

function! easycomplete#sources#deno#constructor(opt, ctx)
call easycomplete#RegisterLspServer(a:opt, {
\ 'name': 'deno',
\ 'cmd': {server_info->[easycomplete#installer#GetCommand(a:opt['name']), 'lsp']},
\ 'root_uri':{server_info -> easycomplete#util#GetDefaultRootUri()},
\ 'initialization_options' : {
\ 'enable': v:true,
\ 'lint': v:true,
\ 'unstable': v:true,
\ 'importMap': v:null,
\ 'codeLens': {
\ 'implementations': v:true,
\ 'references': v:true,
\ 'referencesAllFunctions': v:true,
\ 'test': v:true,
\ 'testArgs': ['--allow-all'],
\ },
\ "suggest": {
\ "autoImports": v:true,
\ "completeFunctionCalls": v:true,
\ "names": v:true,
\ "paths": v:true,
\ "imports": {
\ "autoDiscover": v:false,
\ "hosts": {
\ "https://deno.land/": v:true,
\ },
\ },
\ },
\ 'config': v:null,
\ 'internalDebug': v:false,
\ },
\ 'config': {'refresh_pattern': '\(\$[a-zA-Z0-9_:]*\|\k\+\)$'},
\ 'allowlist': a:opt["whitelist"],
\ 'blocklist' : [],
\ 'workspace_config' : {},
\ 'semantic_highlight' : {},
\ })
if easycomplete#sources#deno#IsDenoProject()
if easycomplete#sources#deno#ok()
call easycomplete#RegisterLspServer(a:opt, {
\ 'name': 'deno',
\ 'cmd': {server_info->[easycomplete#installer#GetCommand(a:opt['name']), 'lsp']},
\ 'root_uri':{server_info -> easycomplete#util#GetDefaultRootUri()},
\ 'initialization_options' : {
\ 'enable': v:true,
\ 'lint': v:true,
\ 'unstable': v:true,
\ 'importMap': v:null,
\ 'codeLens': {
\ 'implementations': v:true,
\ 'references': v:true,
\ 'referencesAllFunctions': v:true,
\ 'test': v:true,
\ 'testArgs': ['--allow-all'],
\ },
\ "suggest": {
\ "autoImports": v:true,
\ "completeFunctionCalls": v:true,
\ "names": v:true,
\ "paths": v:true,
\ "imports": {
\ "autoDiscover": v:false,
\ "hosts": {
\ "https://deno.land/": v:true,
\ },
\ },
\ },
\ 'config': v:null,
\ 'internalDebug': v:false,
\ },
\ 'config': {'refresh_pattern': '\(\$[a-zA-Z0-9_:]*\|\k\+\)$'},
\ 'allowlist': a:opt["whitelist"],
\ 'blocklist' : [],
\ 'workspace_config' : {},
\ 'semantic_highlight' : {},
\ })
call easycomplete#UnRegisterSource("ts")

augroup easycomplete#DenoCommand
command! DenoCache :call easycomplete#sources#deno#cache()
augroup END
endif
endfunction

function! easycomplete#sources#deno#ok()
if easycomplete#sources#deno#IsTSOrJSFiletype() && easycomplete#sources#deno#IsDenoProject()
return v:true
else
call easycomplete#UnRegisterSource("deno")
return v:false
endif
endfunction

Expand All @@ -57,6 +67,39 @@ function! easycomplete#sources#deno#GotoDefinition(...)
return easycomplete#DoLspDefinition(s:file_extensions)
endfunction

function! easycomplete#sources#deno#cache()
if !easycomplete#sources#deno#ok()
call s:log("Please do `deno cache` under a deno project!")
return
endif
let current_file = easycomplete#util#GetCurrentFullName()
let deno_command = easycomplete#installer#GetCommand("deno")
let exec_command = deno_command . " cache " . current_file
call s:log('deno cache ' . current_file . ' ......')
if g:env_is_vim
let l:bufnr = term_start(exec_command, {
\ 'hidden' : 1,
\ 'term_rows': 5,
\ 'term_name':'deno_cache',
\ })
let l:job = term_getjob(l:bufnr)
if l:job != v:null
call job_setoptions(l:job, {'exit_cb': function('s:CachePost', [])})
endif
else
call termopen(exec_command, {
\ 'hidden' : 1,
\ 'term_rows': 5,
\ 'term_name':'deno_cache',
\ 'on_exit': function('s:CachePost', []),
\ })

This comment has been minimized.

Copy link
@jayli

jayli Feb 12, 2022

Author Owner

#142 142

endif
endfunction

function! s:CachePost(job, code, ...) abort
call s:log('`deno cache` Finished!')
endfunction

function! easycomplete#sources#deno#filter(matches)
let ctx = easycomplete#context()
let matches = a:matches
Expand Down
10 changes: 8 additions & 2 deletions doc/easycomplete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ All commands:
| :EasyCompleteProfileStart | Start record diagnostics message |
| :EasyCompleteProfileStop | Stop record diagnostics message |
| :EasyCompleteLint | Do diagnostic |
| :DenoCache | Do Deno Cache for downloading modules |

===============================================================================

Expand All @@ -100,13 +101,13 @@ Most Language require LSP Server. Install missing LSP Server with
`:EasyCompleteInstallServer` for current filetype (recommended). LSP Server
will be installed in `~/.config/vim-easycomplete/servers`. >

:EasyCompleteInstall
:InstallLspServer

Or you can install a lsp server with specified plugin name (not recommended).

Take typescript/javascript for example: >

:EasyCompleteInstallServer ts
:InstallLspServer ts

All supported languages:

Expand All @@ -116,6 +117,7 @@ All supported languages:
| buf | keywords & dictionary | No Need | No Need |
| snips | Snippets Support | ultisnips/vim-snippets | No |
| ts | JavaScript/TypeScript | tsserver | Yes |
| deno | JavaScript/TypeScript | deno | Yes |
| vim | Vim | vim-language-server | Yes |
| cpp | C/C++ | ccls | Yes |
| css | CSS | css-languageserver | Yes |
Expand All @@ -134,6 +136,8 @@ All supported languages:
| kt | Kotlin | kotlin-language-server | Yes |
| grvy | Groovy | groovy-language-server | Yes |
| cmake | cmake | cmake-language-server | Yes |
| dart | dart | analysis...-snapshot | Yes |
| php | php | intelephense | Yes |

EasyComplete needs ultisnips and vim-snippets for snippets support if you want.
This two plugin is compatible with EasyComplete out of the box. Install with
Expand All @@ -144,6 +148,8 @@ vim-plug: >

===============================================================================

Get More Info: <https://github.com/jayli/vim-easycomplete>

Help

[WIP] If you have bug reports or feature suggestions, please use the issue tracker
Expand Down

0 comments on commit f1e5ce8

Please sign in to comment.