-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Determine the current workspace directory #923
Changes from all commits
02a415c
2670130
d353bb1
4e90d8d
88840ac
847badd
b8c9303
a30d9cd
1cdac34
36ffca4
ddaac83
199586a
b287d30
2738a8b
dd46e9e
c05e531
619e887
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,7 +327,7 @@ endfunction | |
" Utility functions | ||
""""""""""""""""""""""" | ||
function! s:isOpenInCurrentWindow(filePath) | ||
return expand('%:p') == a:filePath | ||
return phpactor#_path() == a:filePath | ||
endfunction | ||
|
||
function! phpactor#_switchToBufferOrEdit(filePath) | ||
|
@@ -353,7 +353,15 @@ function! phpactor#_source() | |
endfunction | ||
|
||
function! phpactor#_path() | ||
return expand('%:p') | ||
let l:path = expand('%:p') | ||
|
||
if filereadable(l:path) || stridx(l:path, '/') == 0 | ||
return l:path | ||
endif | ||
|
||
" todo if empty path | ||
" | ||
return printf('%s/%s', g:phpactorInitialCwd, l:path) | ||
endfunction | ||
|
||
function! s:getStartOffsetFromMark(mark, linewise) | ||
|
@@ -435,14 +443,53 @@ endfunction | |
" RPC -->-->-->-->-->-- | ||
""""""""""""""""""""""" | ||
|
||
function! s:searchDirectoryUpwardForRootPatterns(initialDirectory, workspaceRootPatterns, fallbackDirectory) | ||
if index(g:phpactorGlobalRootPatterns, '/') < 0 | ||
call add(g:phpactorGlobalRootPatterns, '/') | ||
endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add some commentry to this function? not to concerned however (would have just saved me doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have explained it in doc comment added in ftplugin. It forces excluding system root directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, it checks if |
||
|
||
let l:directory = a:initialDirectory | ||
|
||
while index(g:phpactorGlobalRootPatterns, l:directory) < 0 | ||
if s:directoryMatchesToPatterns(l:directory, a:workspaceRootPatterns) | ||
return l:directory | ||
endif | ||
|
||
let l:directory = fnamemodify(l:directory, ':h') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would still detect the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment below |
||
endwhile | ||
|
||
if index(g:phpactorGlobalRootPatterns, l:directory) >= 0 | ||
let l:directory = a:fallbackDirectory | ||
endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that there these patterns are used also to exclude them. The one caveat is a case when What do you think about writing some tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - testing is relatively easy with https://github.com/junegunn/vader.vim tests are in |
||
|
||
return l:directory | ||
endfunction | ||
|
||
function s:directoryMatchesToPatterns(directory, patterns) abort | ||
for l:pattern in a:patterns | ||
if (filereadable(a:directory .'/'. l:pattern)) | ||
return v:true | ||
endif | ||
endfor | ||
|
||
return v:false | ||
endfunction | ||
|
||
function! phpactor#rpc(action, arguments) | ||
" Remove any existing output in the message window | ||
execute ':redraw' | ||
|
||
let request = { "action": a:action, "parameters": a:arguments } | ||
|
||
let cmd = g:phpactorPhpBin . ' ' . g:phpactorbinpath . ' rpc --working-dir=' . g:phpactorInitialCwd | ||
let result = system(cmd, json_encode(request)) | ||
let l:workspaceDir = s:searchDirectoryUpwardForRootPatterns( | ||
\ fnamemodify(phpactor#_path(), ':h'), | ||
\ g:phpactorProjectRootPatterns, | ||
\ g:phpactorInitialCwd | ||
\) | ||
|
||
let l:cmd = g:phpactorPhpBin . ' ' . g:phpactorbinpath . ' rpc --working-dir=' . l:workspaceDir | ||
|
||
let result = system(l:cmd, json_encode(request)) | ||
|
||
if (v:shell_error == 0) | ||
try | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what problem does this change solve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed a while to remember its origin after week.
It came directly from one of test cases that did not pass. I have explained it in #923 (comment).