Last active
July 11, 2018 07:41
-
-
Save takeshy/47e08bf8036cc04f959a902f36389ca2 to your computer and use it in GitHub Desktop.
typescriptのimport先のファイルの読み込み
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! ReadFile() abort | |
let s:currentPos = col('.') | |
let s:colNum = s:currentPos - 1 | |
let s:lastPos = len(getline('.')) | |
let s:fileName = '' | |
let s:ext = '.' . expand("%:e") | |
while s:colNum > -1 | |
if getline('.')[s:colNum] =~ "\['\"\]" | |
break | |
end | |
let s:fileName = getline('.')[s:colNum] . s:fileName | |
let s:colNum = s:colNum - 1 | |
endwhile | |
while s:currentPos < s:lastPos | |
if getline('.')[s:currentPos] =~ "\['\"\]" | |
break | |
end | |
let s:fileName = s:fileName . getline('.')[s:currentPos] | |
let s:currentPos = s:currentPos + 1 | |
endwhile | |
let s:prevPath = "" | |
let s:dirs = split(expand("%:p:h"), '/') | |
if s:fileName =~ "^\\." | |
let s:fullName = simplify(expand("%:p:h") . '/' . s:fileName) | |
else | |
for name in s:dirs | |
let s:prevPath = s:prevPath . '/' . name | |
if (name == "ts" && (s:ext == ".ts" || s:ext == ".tsx")) || (name == "es6") | |
break | |
endif | |
endfor | |
let s:fullName = simplify(s:prevPath . '/' . s:fileName) | |
endif | |
if !filereadable(s:fullName) | |
if isdirectory(s:fullName) | |
let s:fullName = s:fullName . '/index' . s:ext | |
else | |
if filereadable(s:fullName. '.ts') | |
let s:fullName = s:fullName . '.ts' | |
else | |
if filereadable(s:fullName. '.tsx') | |
let s:fullName = s:fullName . '.tsx' | |
else | |
if filereadable(s:fullName. '.d.ts') | |
let s:fullName = s:fullName . '.d.ts' | |
else | |
let s:fullName = s:fullName . s:ext | |
endif | |
endif | |
endif | |
endif | |
endif | |
execute ':e ' . s:fullName | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment