Permalink
Browse files

Import completion

* Add navto command client

* (wip) navto func

* Add search command

* wip

* move import functions

* Replace identifier

* add import command

* Add docs

* wip

* refactor

* Move test files

* Modify runner

* Add test

* Add cache to external-check

* Add getImportDeclarations test

* Modify runner

* Add doc
  • Loading branch information...
Quramy committed May 10, 2016
1 parent 6e9bb5e commit 56ab358c147b91fbe32c43972e4f5d7951423025
Showing with 758 additions and 76 deletions.
  1. +40 −0 README.md
  2. +90 −1 autoload/tsuquyomi.vim
  3. +294 −0 autoload/tsuquyomi/es6import.vim
  4. +3 −1 autoload/tsuquyomi/tsClient.vim
  5. +5 −0 doc/tsuquyomi.jax
  6. +5 −0 doc/tsuquyomi.txt
  7. +5 −0 ftplugin/typescript.vim
  8. +3 −3 runtest.sh
  9. +28 −0 test/.vimrc
  10. +29 −0 test/_runner
  11. +45 −0 test/es6import/vest/checkExternalModule.spec.vim
  12. +104 −0 test/es6import/vest/getImportDeclarations.spec.vim
  13. +1 −0 test/es6import/vest/resources/importDecPatterns/empty.ts
  14. +2 −0 test/es6import/vest/resources/importDecPatterns/explictAlias.ts
  15. +4 −0 test/es6import/vest/resources/importDecPatterns/multiAlias.ts
  16. +2 −0 test/es6import/vest/resources/importDecPatterns/multiDec.ts
  17. +7 −0 test/es6import/vest/resources/importDecPatterns/multiline.ts
  18. +5 −0 test/es6import/vest/resources/importDecPatterns/noDec.ts
  19. +1 −0 test/es6import/vest/resources/importDecPatterns/simple.ts
  20. +2 −0 test/es6import/vest/resources/importDecPatterns/some-module.ts
  21. +11 −0 test/es6import/vest/resources/importDecPatterns/tsconfig.json
  22. +19 −0 test/es6import/vest/resources/variousModules.d.ts
  23. 0 { → test/tsClient}/vest/resources/SimpleModule.ts
  24. 0 { → test/tsClient}/vest/resources/SimpleModule_writing.ts
  25. 0 { → test/tsClient}/vest/resources/definitionTest.ts
  26. 0 { → test/tsClient}/vest/resources/referencesTestA.ts
  27. 0 { → test/tsClient}/vest/resources/referencesTestB.ts
  28. 0 { → test/tsClient}/vest/resources/renameTest.ts
  29. 0 { → test/tsClient}/vest/resources/samplePrjs/errorPrj/main.ts
  30. 0 { → test/tsClient}/vest/resources/samplePrjs/errorPrj/sub.ts
  31. 0 { → test/tsClient}/vest/resources/samplePrjs/errorPrj/tsconfig.json
  32. 0 { → test/tsClient}/vest/resources/samplePrjs/prj001/main.ts
  33. 0 { → test/tsClient}/vest/resources/samplePrjs/prj001/tsconfig.json
  34. 0 { → test/tsClient}/vest/resources/signatureHelpTest_overload.ts
  35. 0 { → test/tsClient}/vest/resources/signatureHelpTest_writing.ts
  36. 0 { → test/tsClient}/vest/sendCommand.spec.vim
  37. 0 { → test/tsClient}/vest/sendRequest.spec.vim
  38. 0 { → test/tsClient}/vest/startTss.spec.vim
  39. +1 −1 { → test/tsClient}/vest/tsCompletionEntryDetails.spec.vim
  40. +3 −3 { → test/tsClient}/vest/tsCompletions.spec.vim
  41. +2 −2 { → test/tsClient}/vest/tsDefinition.spec.vim
  42. +1 −1 { → test/tsClient}/vest/tsGeterr.spec.vim
  43. +2 −2 { → test/tsClient}/vest/tsGeterrForProject.spec.vim
  44. +1 −1 { → test/tsClient}/vest/tsNavBar.spec.vim
  45. +25 −0 test/tsClient/vest/tsNavto.spec.vim
  46. +1 −1 { → test/tsClient}/vest/tsProjectInfo.spec.vim
  47. +1 −1 { → test/tsClient}/vest/tsQuickinfo.spec.vim
  48. +3 −3 { → test/tsClient}/vest/tsReferences.spec.vim
  49. +1 −1 { → test/tsClient}/vest/tsReload.spec.vim
  50. +10 −10 { → test/tsClient}/vest/tsRename.spec.vim
  51. +2 −2 { → test/tsClient}/vest/tsSignatureHelp.spec.vim
  52. +0 −30 vest/.vimrc
  53. +0 −13 vest/_runner
View
@@ -124,6 +124,9 @@ Type `<C-^>` in normal mode or visual mode, Tsuquyomi shows a list of location w
Alternatively, call the Ex command `:TsuquyomiReferences`.
### Keyword search
Call the Ex command `:TsuquyomiSearch {keyword}` to get the list of locations which contain the keyword. This command searches the keyword from opened or referenced files in your project.
### Show quickfix
When a buffer is saved, Tsuquyomi checks syntax and semantics.
And if it contains errors, Tsuquyomi shows them to Vim quickfix window.
@@ -245,6 +248,43 @@ And execute the following command, you can confirm the path of tsserver:
:echo tsuquyomi#config#tsscmd()
```
### Create es6 import declaration
**It's highly experimental**
For example, if your buffer is the following state:
```ts
readFile('hoge', 'utf-8', (err, content) => {
if(!err) console.log(content);
});
```
Move cursor onto `readFile` and call `:TsuImport`, so Tsuquyomi appends the import declaration.
```ts
import { readFile } from 'fs';
readFile('hoge', 'utf-8', (err, content) => {
if(!err) console.log(content);
});
```
This command has the following limitation:
* This command searches aliases from only files already opened or referenced
* This command searches aliases which are exported explicitly.
In other words, if your project has the following 2 files, `import { foo } from './lib';` is a valid declaration, but Tsuquyomi creates only `import { foo } from './lib/foo';`.
```ts
/* lib/index.ts */
export * from './foo';
```
```ts
/* lib/foo.ts */
export const var foo = 'FOO'
```
### More details
If you want more details, please see [doc](doc/tsuquyomi.txt).
View
@@ -76,7 +76,7 @@ function! s:flash()
endfunction
function! s:is_valid_identifier(symbol_str)
return a:symbol_str =~ '[A-Za-z_\$][A-Za-z_\$0-9]*'
return a:symbol_str =~ '^[A-Za-z_\$][A-Za-z_\$0-9]*$'
endfunction
" ### Utilites }}}
@@ -718,6 +718,95 @@ function! tsuquyomi#navBar()
endfunction
" #### NavBar }}}
" #### Navto {{{
function! tsuquyomi#navto(term, kindModifiers, matchKindType)
if len(a:term) < 3
echom "[Tsuquyomi] search term's length should be greater than 3."
return [[], 0]
endif
if len(s:checkOpenAndMessage([expand('%:p')])[1])
return [[], 0]
endif
call s:flash()
let l:filename = expand('%:p')
let result_list = tsuquyomi#tsClient#tsNavto(tsuquyomi#bufManager#normalizePath(l:filename), a:term, 100)
if len(result_list)
let list = []
for result in result_list
let flg = 1
if a:matchKindType == 1
let flg = flg && (result.matchKind=='prefix' || result.matchKind=='exact')
elseif a:matchKindType == 2
let flg = flg && (result.matchKind=='exact')
endif
if a:kindModifiers != ''
let flg = flg && has_key(result, 'kindModifiers') && result.kindModifiers=~a:kindModifiers
endif
if flg
call add(list, result)
endif
endfor
return [list, 1]
else
echohl Error
echom "[Tsuquyomi] Nothing was hit."
echohl none
return [[], 0]
endif
endfunction
function! tsuquyomi#navtoByLoclist(term, kindModifiers, matchKindType)
let [result_list, res_code] = tsuquyomi#navto(a:term, a:kindModifiers, a:matchKindType)
if res_code
let l:location_list = []
for navtoItem in result_list
let text = navtoItem.kind.' '.navtoItem.name
if has_key(navtoItem, 'kindModifiers')
let text = navtoItem.kindModifiers.' '.text
endif
if has_key(navtoItem, 'containerName')
if has_key(navtoItem, 'containerKind')
let text = text.' in '.navtoItem.containerKind.' '.navtoItem.containerName
else
let text = text.' in '.navtoItem.containerName
endif
endif
let l:location_info = {
\'filename': navtoItem.file,
\'lnum': navtoItem.start.line,
\'col': navtoItem.start.offset,
\'text': text
\}
call add(l:location_list, l:location_info)
endfor
if(len(l:location_list) > 0)
call setloclist(0, l:location_list, 'r')
lwindow
endif
endif
endfunction
function! tsuquyomi#navtoByLoclistContain(term)
call tsuquyomi#navtoByLoclist(a:term, '', 0)
endfunction
function! tsuquyomi#navtoByLoclistPrefix(term)
call tsuquyomi#navtoByLoclist(a:term, '', 1)
endfunction
function! tsuquyomi#navtoByLoclistExact(term)
call tsuquyomi#navtoByLoclist(a:term, '', 2)
endfunction
" #### Navto }}}
" ### Public functions }}}
let &cpo = s:save_cpo
Oops, something went wrong.

0 comments on commit 56ab358

Please sign in to comment.