diff options
-rw-r--r-- | autoload/ale/c.vim | 72 | ||||
-rw-r--r-- | autoload/ale/completion.vim | 38 | ||||
-rw-r--r-- | autoload/ale/preview.vim | 29 | ||||
-rw-r--r-- | doc/ale.txt | 34 | ||||
-rw-r--r-- | test/completion/test_lsp_completion_parsing.vader | 34 | ||||
-rw-r--r-- | test/test_c_flag_parsing.vader | 181 | ||||
-rw-r--r-- | test/test_find_references.vader | 22 |
7 files changed, 314 insertions, 96 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index 5cf4c690..6f18ce4c 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -84,10 +84,10 @@ function! ale#c#ExpandAtArgs(path_prefix, raw_split_lines) abort let l:path = join(split(l:option, '\zs')[1:], '') " Make path absolute - if stridx(l:path, s:sep) != 0 && stridx(l:path, '/') != 0 + if !ale#path#IsAbsolute(l:path) let l:rel_path = substitute(l:path, '"', '', 'g') let l:rel_path = substitute(l:rel_path, '''', '', 'g') - let l:path = a:path_prefix . s:sep . l:rel_path + let l:path = ale#path#GetAbsPath(a:path_prefix, l:rel_path) endif " Read the file and add all the arguments @@ -133,6 +133,7 @@ function! ale#c#ParseCFlags(path_prefix, cflag_line) abort \ || stridx(l:option, '-isystem') == 0 \ || stridx(l:option, '-idirafter') == 0 \ || stridx(l:option, '-iframework') == 0 + \ || stridx(l:option, '-include') == 0 if stridx(l:option, '-I') == 0 && l:option isnot# '-I' let l:arg = join(split(l:option, '\zs')[2:], '') let l:option = '-I' @@ -142,10 +143,12 @@ function! ale#c#ParseCFlags(path_prefix, cflag_line) abort endif " Fix relative paths if needed - if stridx(l:arg, s:sep) != 0 && stridx(l:arg, '/') != 0 + if !ale#path#IsAbsolute(l:arg) let l:rel_path = substitute(l:arg, '"', '', 'g') let l:rel_path = substitute(l:rel_path, '''', '', 'g') - let l:arg = ale#Escape(a:path_prefix . s:sep . l:rel_path) + let l:arg = ale#Escape( + \ ale#path#GetAbsPath(a:path_prefix, l:rel_path) + \) endif call add(l:cflags_list, l:option) @@ -268,6 +271,10 @@ if !exists('s:compile_commands_cache') let s:compile_commands_cache = {} endif +function! ale#c#ResetCompileCommandsCache() abort + let s:compile_commands_cache = {} +endfunction + function! s:GetLookupFromCompileCommandsFile(compile_commands_file) abort let l:empty = [{}, {}] @@ -298,9 +305,20 @@ function! s:GetLookupFromCompileCommandsFile(compile_commands_file) abort let l:dir_lookup = {} for l:entry in (type(l:raw_data) is v:t_list ? l:raw_data : []) + let l:filename = ale#path#GetAbsPath(l:entry.directory, l:entry.file) + + " Store a key for lookups by the absolute path to the filename. + let l:file_lookup[l:filename] = get(l:file_lookup, l:filename, []) + [l:entry] + + " Store a key for fuzzy lookups by the absolute path to the directory. + let l:dirname = fnamemodify(l:filename, ':h') + let l:dir_lookup[l:dirname] = get(l:dir_lookup, l:dirname, []) + [l:entry] + + " Store a key for fuzzy lookups by just the basename of the file. let l:basename = tolower(fnamemodify(l:entry.file, ':t')) let l:file_lookup[l:basename] = get(l:file_lookup, l:basename, []) + [l:entry] + " Store a key for fuzzy lookups by just the basename of the directory. let l:dirbasename = tolower(fnamemodify(l:entry.directory, ':p:h:t')) let l:dir_lookup[l:dirbasename] = get(l:dir_lookup, l:dirbasename, []) + [l:entry] endfor @@ -326,17 +344,41 @@ function! ale#c#GetCompileCommand(json_item) abort endfunction function! ale#c#ParseCompileCommandsFlags(buffer, file_lookup, dir_lookup) abort + let l:buffer_filename = ale#path#Simplify(expand('#' . a:buffer . ':p')) + let l:basename = tolower(fnamemodify(l:buffer_filename, ':t')) + " Look for any file in the same directory if we can't find an exact match. + let l:dir = fnamemodify(l:buffer_filename, ':h') + " Search for an exact file match first. - let l:basename = tolower(expand('#' . a:buffer . ':t')) - let l:file_list = get(a:file_lookup, l:basename, []) + let l:file_list = get(a:file_lookup, l:buffer_filename, []) + " Try the absolute path to the directory second. + let l:dir_list = get(a:dir_lookup, l:dir, []) + + if empty(l:file_list) && empty(l:dir_list) + " If we can't find matches with the path to the file, try a + " case-insensitive match for any similarly-named file. + let l:file_list = get(a:file_lookup, l:basename, []) + + " If we can't find matches with the path to the directory, try a + " case-insensitive match for anything in similarly-named directory. + let l:dir_list = get(a:dir_lookup, tolower(fnamemodify(l:dir, ':t')), []) + endif + " A source file matching the header filename. let l:source_file = '' if empty(l:file_list) && l:basename =~? '\.h$\|\.hpp$' for l:suffix in ['.c', '.cpp'] - let l:key = fnamemodify(l:basename, ':r') . l:suffix + " Try to find a source file by an absolute path first. + let l:key = fnamemodify(l:buffer_filename, ':r') . l:suffix let l:file_list = get(a:file_lookup, l:key, []) + if empty(l:file_list) + " Look fuzzy matches on the basename second. + let l:key = fnamemodify(l:basename, ':r') . l:suffix + let l:file_list = get(a:file_lookup, l:key, []) + endif + if !empty(l:file_list) let l:source_file = l:key break @@ -345,27 +387,25 @@ function! ale#c#ParseCompileCommandsFlags(buffer, file_lookup, dir_lookup) abort endif for l:item in l:file_list + let l:filename = ale#path#GetAbsPath(l:item.directory, l:item.file) + " Load the flags for this file, or for a source file matching the " header file. if ( - \ bufnr(l:item.file) is a:buffer + \ bufnr(l:filename) is a:buffer \ || ( \ !empty(l:source_file) - \ && l:item.file[-len(l:source_file):] is? l:source_file + \ && l:filename[-len(l:source_file):] is? l:source_file \ ) \) return ale#c#ParseCFlags(l:item.directory, ale#c#GetCompileCommand(l:item)) endif endfor - " Look for any file in the same directory if we can't find an exact match. - let l:dir = ale#path#Simplify(expand('#' . a:buffer . ':p:h')) - - let l:dirbasename = tolower(expand('#' . a:buffer . ':p:h:t')) - let l:dir_list = get(a:dir_lookup, l:dirbasename, []) - for l:item in l:dir_list - if ale#path#Simplify(fnamemodify(l:item.file, ':h')) is? l:dir + let l:filename = ale#path#GetAbsPath(l:item.directory, l:item.file) + + if ale#path#Simplify(fnamemodify(l:filename, ':h')) is? l:dir return ale#c#ParseCFlags(l:item.directory, ale#c#GetCompileCommand(l:item)) endif endfor diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index a273d4e1..f6a0c350 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -540,7 +540,8 @@ function! ale#completion#ParseLSPCompletions(response) abort " Don't use LSP items with additional text edits when autoimport for " completions is turned off. - if has_key(l:item, 'additionalTextEdits') && !g:ale_completion_autoimport + if !empty(get(l:item, 'additionalTextEdits')) + \&& !g:ale_completion_autoimport continue endif @@ -562,31 +563,32 @@ function! ale#completion#ParseLSPCompletions(response) abort let l:text_changes = [] for l:edit in l:item.additionalTextEdits - let l:range = l:edit.range call add(l:text_changes, { \ 'start': { - \ 'line': l:range.start.line + 1, - \ 'offset': l:range.start.character + 1, + \ 'line': l:edit.range.start.line + 1, + \ 'offset': l:edit.range.start.character + 1, \ }, \ 'end': { - \ 'line': l:range.end.line + 1, - \ 'offset': l:range.end.character + 1, + \ 'line': l:edit.range.end.line + 1, + \ 'offset': l:edit.range.end.character + 1, \ }, \ 'newText': l:edit.newText, \}) endfor - let l:changes = [{ - \ 'fileName': expand('#' . l:buffer . ':p'), - \ 'textChanges': l:text_changes, - \}] - \ - let l:result.user_data = json_encode({ - \ 'codeActions': [{ - \ 'description': 'completion', - \ 'changes': l:changes, - \ }], - \ }) + if !empty(l:text_changes) + let l:result.user_data = json_encode({ + \ 'codeActions': [{ + \ 'description': 'completion', + \ 'changes': [ + \ { + \ 'fileName': expand('#' . l:buffer . ':p'), + \ 'textChanges': l:text_changes, + \ } + \ ], + \ }], + \}) + endif endif call add(l:results, l:result) @@ -900,6 +902,8 @@ function! ale#completion#Done() abort endfunction augroup ALECompletionActions + autocmd! + autocmd CompleteDone * call ale#completion#HandleUserData(v:completed_item) augroup END diff --git a/autoload/ale/preview.vim b/autoload/ale/preview.vim index faf45cb0..8b94aa7a 100644 --- a/autoload/ale/preview.vim +++ b/autoload/ale/preview.vim @@ -1,14 +1,22 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Preview windows for showing whatever information in. -if !has_key(s:, 'last_selection_list') - let s:last_selection_list = [] +if !has_key(s:, 'last__list') + let s:last_list = [] endif -if !has_key(s:, 'last_selection_open_in') - let s:last_selection_open_in = 'current-buffer' +if !has_key(s:, 'last_options') + let s:last_options = {} endif +function! ale#preview#SetLastSelection(item_list, options) abort + let s:last_list = a:item_list + let s:last_options = { + \ 'open_in': get(a:options, 'open_in', 'current-buffer'), + \ 'use_relative_paths': get(a:options, 'use_relative_paths', 0), + \} +endfunction + " Open a preview window and show some lines in it. " A second argument can be passed as a Dictionary with options. They are... " @@ -81,19 +89,14 @@ function! ale#preview#ShowSelection(item_list, ...) abort let b:ale_preview_item_list = a:item_list let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer') - " Remove the last preview - let s:last_selection_list = b:ale_preview_item_list - let s:last_selection_open_in = b:ale_preview_item_open_in + " Remember preview state, so we can repeat it later. + call ale#preview#SetLastSelection(a:item_list, l:options) endfunction function! ale#preview#RepeatSelection() abort - if empty(s:last_selection_list) - return + if !empty(s:last_list) + call ale#preview#ShowSelection(s:last_list, s:last_options) endif - - call ale#preview#ShowSelection(s:last_selection_list, { - \ 'open_in': s:last_selection_open_in, - \}) endfunction function! s:Open(open_in) abort diff --git a/doc/ale.txt b/doc/ale.txt index ac51e466..da430042 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -562,15 +562,9 @@ displayed. ------------------------------------------------------------------------------- 5.4 Find References *ale-find-references* -ALE supports finding references for symbols though any enabled LSP linters. -ALE will display a preview window showing the places where a symbol is -referenced in a codebase when a command is run. The following commands are -supported: - -|ALEFindReferences| - Find references for the word under the cursor. - -Options: - `-relative` Show file paths in the results relative to the working dir +ALE supports finding references for symbols though any enabled LSP linters +with the |ALEFindReferences| command. See the documentation for the command +for a full list of options. ------------------------------------------------------------------------------- 5.5 Hovering *ale-hover* @@ -613,13 +607,9 @@ Documentation for symbols at the cursor can be retrieved using the ------------------------------------------------------------------------------- 5.6 Symbol Search *ale-symbol-search* -ALE supports searching for workspace symbols via LSP linters. The following -commands are supported: - -|ALESymbolSearch| - Search for symbols in the workspace. - -Options: - `-relative` Show file paths in the results relative to the working dir +ALE supports searching for workspace symbols via LSP linters with the +|ALESymbolSearch| command. See the documentation for the command +for a full list of options. =============================================================================== 6. Global Options *ale-options* @@ -871,7 +861,7 @@ g:ale_default_navigation *g:ale_default_navigation* Default: `'buffer'` The default method for navigating away from the current buffer to another - buffer, such as for |ALEFindReferences:|, or |ALEGoToDefinition|. + buffer, such as for |ALEFindReferences|, or |ALEGoToDefinition|. g:ale_disable_lsp *g:ale_disable_lsp* @@ -2911,13 +2901,20 @@ ALEFindReferences *ALEFindReferences* The default method used for navigating to a new location can be changed by modifying |g:ale_default_navigation|. + You can add `-relative` to the command to view results with relatives paths, + instead of absolute paths. + The selection can be opened again with the |ALERepeatSelection| command. You can jump back to the position you were at before going to a reference of something with jump motions like CTRL-O. See |jump-motions|. A plug mapping `<Plug>(ale_find_references)` is defined for this command. + You can define additional plug mapping with any additional options you want + like so: > + nnoremap <silent> <Plug>(my_mapping) :ALEFindReferences -relative<Return> +< ALEFix *ALEFix* @@ -3029,6 +3026,9 @@ ALESymbolSearch `<query>` *ALESymbolSearch* The arguments provided to this command will be used as a search query for finding symbols in the workspace, such as functions, types, etc. + You can add `-relative` to the command to view results with relatives paths, + instead of absolute paths. + *:ALELint* ALELint *ALELint* diff --git a/test/completion/test_lsp_completion_parsing.vader b/test/completion/test_lsp_completion_parsing.vader index 8b8b41c7..b8e71320 100644 --- a/test/completion/test_lsp_completion_parsing.vader +++ b/test/completion/test_lsp_completion_parsing.vader @@ -609,6 +609,7 @@ Execute(Should handle completion messages with additionalTextEdits when ale_comp Execute(Should not handle completion messages with additionalTextEdits when ale_completion_autoimport is turned off): let g:ale_completion_autoimport = 0 + let b:ale_completion_info = {'line': 30} AssertEqual \ [], @@ -645,3 +646,36 @@ Execute(Should not handle completion messages with additionalTextEdits when ale_ \ ], \ }, \ }) + +Execute(Should still handle completion messages with empty additionalTextEdits with ale_completion_autoimport turned off): + let g:ale_completion_autoimport = 0 + + AssertEqual + \ [ + \ { + \ 'word': 'next_callback', + \ 'menu': 'PlayTimeCallback', + \ 'info': '', + \ 'kind': 'v', + \ 'icase': 1, + \ } + \ ], + \ ale#completion#ParseLSPCompletions({ + \ 'id': 226, + \ 'jsonrpc': '2.0', + \ 'result': { + \ 'isIncomplete': v:false, + \ 'items': [ + \ { + \ 'detail': 'PlayTimeCallback', + \ 'filterText': 'next_callback', + \ 'insertText': 'next_callback', + \ 'insertTextFormat': 1, + \ 'kind': 6, + \ 'label': ' next_callback', + \ 'sortText': '3ee19999next_callback', + \ 'additionalTextEdits': [], + \ }, + \ ], + \ }, + \ }) diff --git a/test/test_c_flag_parsing.vader b/test/test_c_flag_parsing.vader index e9830db8..6656d508 100644 --- a/test/test_c_flag_parsing.vader +++ b/test/test_c_flag_parsing.vader @@ -178,44 +178,164 @@ Execute(ParseCompileCommandsFlags should tolerate empty values): Execute(ParseCompileCommandsFlags should parse some basic flags): silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) + " We should read the absolute path filename entry, not the other ones. AssertEqual \ '-I ' . ale#path#Simplify('/usr/include/xmms2'), - \ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [ + \ ale#c#ParseCompileCommandsFlags( + \ bufnr(''), \ { - \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), - \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') - \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' - \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), - \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'): [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ }, + \ ], + \ "xmms2-mpris.c": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/ignoreme') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ }, + \ ], \ }, - \ ] }, {}) + \ { + \ ale#path#Simplify('/foo/bar/xmms2-mpris/src'): [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris/src'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/ignoreme') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': 'other.c', + \ }, + \ ], + \ "src": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/ignoreme') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), + \ }, + \ ], + \ }, + \ ) -Execute(ParseCompileCommandsFlags should tolerate items without commands): +Execute(ParseCompileCommandsFlags should fall back to files with the same name): silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) + " We should prefer the basename file flags, not the base dirname flags. AssertEqual - \ '', - \ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [ + \ '-I ' . ale#path#Simplify('/usr/include/xmms2'), + \ ale#c#ParseCompileCommandsFlags( + \ bufnr(''), \ { - \ 'directory': '/foo/bar/xmms2-mpris', - \ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', + \ "xmms2-mpris.c": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ }, + \ ], \ }, - \ ] }, {}) + \ { + \ "src": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/ignoreme') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), + \ }, + \ ], + \ }, + \ ) + +Execute(ParseCompileCommandsFlags should parse flags for exact directory matches): + silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) + + " We should ues the exact directory flags, not the file basename flags. + AssertEqual + \ '-I ' . ale#path#Simplify('/usr/include/xmms2'), + \ ale#c#ParseCompileCommandsFlags( + \ bufnr(''), + \ { + \ "xmms2-mpris.c": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/ignoreme') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ }, + \ ], + \ }, + \ { + \ ale#path#Simplify('/foo/bar/xmms2-mpris/src'): [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris/src'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': 'other.c', + \ }, + \ ], + \ "src": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/ignoreme') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), + \ }, + \ ], + \ }, + \ ) Execute(ParseCompileCommandsFlags should fall back to files in the same directory): silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) AssertEqual \ '-I ' . ale#path#Simplify('/usr/include/xmms2'), - \ ale#c#ParseCompileCommandsFlags(bufnr(''), {}, { "src": [ + \ ale#c#ParseCompileCommandsFlags( + \ bufnr(''), + \ {}, \ { - \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), - \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') - \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' - \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), - \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), + \ "src": [ + \ { + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') + \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), + \ }, + \ ], \ }, - \ ] }) + \ ) + +Execute(ParseCompileCommandsFlags should tolerate items without commands): + silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) + + AssertEqual + \ '', + \ ale#c#ParseCompileCommandsFlags( + \ bufnr(''), + \ { + \ "xmms2-mpris.c": [ + \ { + \ 'directory': '/foo/bar/xmms2-mpris', + \ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', + \ }, + \ ], + \ }, + \ {}, + \ ) Execute(ParseCompileCommandsFlags should take commands from matching .c files for .h files): silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h')) @@ -235,8 +355,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .c files fo \ }, \ ], \ }, - \ { - \ }, + \ {}, \ ) Execute(ParseCompileCommandsFlags should take commands from matching .cpp files for .hpp files): @@ -333,14 +452,15 @@ Execute(ParseCFlags should handle parenthesis and quotes): \ . '-Dtest3=`(" ")` file3.o ' \ ) -Execute(CFlags we want to pass): +Execute(We should include several important flags): AssertEqual - \ '-I ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/inc')) - \ . ' -I ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/include')) - \ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incquote')) - \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incsystem')) + \ '-I ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/inc')) + \ . ' -I ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/include')) + \ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/incquote')) + \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/incsystem')) \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incafter')) - \ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incframework')) + \ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/incframework')) + \ . ' -include ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/foo bar')) \ . ' -Dmacro=value -D macro2 -Bbdir -B bdir2' \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3' \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir' @@ -351,6 +471,7 @@ Execute(CFlags we want to pass): \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), \ 'gcc' \ . ' -Iinc -I include -iquote incquote -isystem incsystem -idirafter incafter -iframework incframework' + \ . ' -include ''foo bar''' \ . ' -Dmacro=value -D macro2 -Bbdir -B bdir2' \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3' \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir' @@ -359,7 +480,7 @@ Execute(CFlags we want to pass): \ . ' -iplugindir=dir -march=native -w' \ ) -Execute(CFlags we dont want to pass): +Execute(We should exclude other flags that cause problems): AssertEqual \ '', \ ale#c#ParseCFlags( @@ -368,7 +489,7 @@ Execute(CFlags we dont want to pass): \ . '-fdump-file=name -fdiagnostics-arg -fno-show-column -fstack-usage' \ ) -Execute(Expanding @file in CFlags): +Execute(We should expand @file in CFlags): AssertEqual \ '-DARGS1 -DARGS2 -O2', \ ale#c#ParseCFlags( diff --git a/test/test_find_references.vader b/test/test_find_references.vader index 9949362a..ca05f631 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -63,6 +63,8 @@ Before: let g:preview_called = 1 let g:item_list = a:item_list let g:options = a:options + + call ale#preview#SetLastSelection(a:item_list, a:options) endfunction After: @@ -110,7 +112,16 @@ Given typescript(Some typescript file): bazxyzxyzxyz Execute(Results should be shown for tsserver responses): - call ale#references#SetMap({3: {}}) + " We should remember these options when we repeat the selection. + call ale#references#SetMap( + \ { + \ 3: { + \ 'ignorethis': 'x', + \ 'open_in': 'tab', + \ 'use_relative_paths': 1, + \ } + \ } + \) call ale#references#HandleTSServerResponse(1, { \ 'command': 'references', \ 'request_seq': 3, @@ -158,8 +169,7 @@ Execute(Results should be shown for tsserver responses): AssertEqual {}, ale#references#GetMap() " We should be able to repeat selections with ALERepeatSelection - let g:ale_item_list = [] - + let g:item_list = [] ALERepeatSelection AssertEqual @@ -170,6 +180,12 @@ Execute(Results should be shown for tsserver responses): \ ], \ g:item_list AssertEqual {}, ale#references#GetMap() + AssertEqual + \ { + \ 'open_in': 'tab', + \ 'use_relative_paths': 1, + \ }, + \ g:options Execute(The preview window should not be opened for empty tsserver responses): call ale#references#SetMap({3: {}}) |