diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 755699f3..9aa5462e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ on: jobs: tests_vim: - name: Tests (Vim) + name: Vim strategy: matrix: os: [macos-latest, ubuntu-latest] @@ -38,7 +38,7 @@ jobs: - run: npm ci --no-save - name: Build binary run: npm run build:binary -- node${{ matrix.node-version }}-${{ matrix.target }}-x64 - - name: Setup Vim + - name: Setup vim uses: thinca/action-setup-vim@v1 id: vim with: @@ -48,7 +48,7 @@ jobs: run: ./scripts/run-vader-tests.sh "${{ steps.vim.outputs.executable }}" tests_neovim: - name: Tests (NeoVim) + name: NeoVim strategy: matrix: os: [macos-latest, ubuntu-latest] @@ -77,7 +77,7 @@ jobs: - run: npm ci --no-save - name: Build binary run: npm run build:binary -- node${{ matrix.node-version }}-${{ matrix.target }}-x64 - - name: Setup Vim + - name: Setup neovim uses: thinca/action-setup-vim@v1 id: vim with: diff --git a/.version b/.version index 98a8b1d1..c219f723 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v3.3.2-beta.26 +v3.4.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index cf82ea3a..044eb0b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# [3.4.0](https://github.com/kkoomen/vim-doge/compare/v3.3.2-beta.26...v3.4.0) (2020-10-24) + +### Bug Fixes + +- **ci:** rename steps name ([9b01428](https://github.com/kkoomen/vim-doge/commit/9b014289dec7cf4e046d7d32dce251adbd7a578b)) + +### Features + +- recreate PR [#104](https://github.com/kkoomen/vim-doge/issues/104) ([9c6e84c](https://github.com/kkoomen/vim-doge/commit/9c6e84cbb43e3d8772704ba68e73acb2eb4ca626)) +- **cpp:** add support for virtual functions ([#41](https://github.com/kkoomen/vim-doge/issues/41)) ([a06e8e9](https://github.com/kkoomen/vim-doge/commit/a06e8e9a7680ee47b405268939f8d08d4e54c805)) + ## [3.3.2-beta.26](https://github.com/kkoomen/vim-doge/compare/v3.3.2-beta.25...v3.3.2-beta.26) (2020-10-24) ### Bug Fixes diff --git a/autoload/doge/pattern.vim b/autoload/doge/pattern.vim index 510b0f5e..282590b6 100644 --- a/autoload/doge/pattern.vim +++ b/autoload/doge/pattern.vim @@ -184,17 +184,20 @@ function! doge#pattern#custom(name) abort " otherwise create a new file with an appropriate path. let l:path = '' for l:p in ['~/.vim', '~/vimfiles'] - if isdirectory(expand(l:p)) - let l:path = expand(l:p) + let l:p = expand(l:p) + if match(&runtimepath, l:p) >= 0 + let l:path = l:p break endif endfor - if has('nvim') && empty(l:path) - let l:path = stdpath('config') - endif - if !empty(l:path) - let l:path .= '/after/ftplugin/' . l:this_ft . '.vim' + if empty(l:path) + if exists('*stdpath') + let l:path = stdpath('config') + else + let l:path = getcwd() + endif endif + let l:path .= '/after/ftplugin/' . l:this_ft . '.vim' if filereadable(l:path) let l:cmd = &showtabline ? 'tabedit' : 'split' call execute(l:cmd . fnameescape(l:path), 'silent!') @@ -204,9 +207,7 @@ function! doge#pattern#custom(name) abort else call execute(&showtabline ? 'tabnew' : 'new', 'silent!') setfiletype vim - if !empty(l:path) - call execute('file ' . fnameescape(l:path), 'silent!') - endif + call execute('file ' . fnameescape(l:path), 'silent!') endif " Generate the template and paste it at the top of the file. diff --git a/ftplugin/cpp.vim b/ftplugin/cpp.vim index 04e155bf..7f358975 100644 --- a/ftplugin/cpp.vim +++ b/ftplugin/cpp.vim @@ -51,7 +51,12 @@ unlet s:class_pattern['parameters'] " Matches (template) function- and class method declarations. " ------------------------------------------------------------------------------ let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { -\ 'nodeTypes': ['function_definition', 'declaration', 'template_declaration'], +\ 'nodeTypes': [ +\ 'function_definition', +\ 'declaration', +\ 'template_declaration', +\ 'function_declarator', +\ ], \}) " ------------------------------------------------------------------------------ diff --git a/package-lock.json b/package-lock.json index 0886295c..f479a174 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vim-doge", - "version": "3.3.2-beta.26", + "version": "3.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e0349b0a..866718b3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "vim-doge", - "version": "3.3.2-beta.26", + "version": "3.4.0", "description": "A Vim polyglot plugin for generating documentation", "scripts": { "release": "release-it", diff --git a/src/parsers/cpp.service.ts b/src/parsers/cpp.service.ts index efac9b3a..6ac9f51e 100644 --- a/src/parsers/cpp.service.ts +++ b/src/parsers/cpp.service.ts @@ -9,6 +9,7 @@ enum NodeType { FIELD_DECLARATION = 'field_declaration', CLASS_SPECIFIER = 'class_specifier', TEMPLATE_DECLARATION = 'template_declaration', + FUNCTION_DECLARATOR = 'function_declarator', } export class CppParserService @@ -41,6 +42,7 @@ export class CppParserService break; } + case NodeType.FUNCTION_DECLARATOR: case NodeType.FUNCTION_DEFINITION: case NodeType.DECLARATION: { this.result = { @@ -52,7 +54,11 @@ export class CppParserService parameters: [], returnType: null, }; - this.runNodeParser(this.parseFunction, node); + if (node.type === NodeType.FUNCTION_DECLARATOR) { + this.runNodeParser(this.parseFunction, node.parent as SyntaxNode); + } else { + this.runNodeParser(this.parseFunction, node); + } break; } @@ -122,10 +128,12 @@ export class CppParserService // Method name. childNode.children .filter((n: SyntaxNode) => - ['identifier', 'scoped_identifier'].includes(n.type), + ['identifier', 'scoped_identifier', 'field_identifier'].includes( + n.type, + ), ) .forEach((n: SyntaxNode) => { - if (n.type === 'identifier') { + if (['identifier', 'field_identifier'].includes(n.type)) { this.result.name = n.text; } diff --git a/test/commands/create-doc-standard.vader b/test/commands/create-doc-standard.vader index 0b8cf125..263210a6 100644 --- a/test/commands/create-doc-standard.vader +++ b/test/commands/create-doc-standard.vader @@ -5,6 +5,9 @@ # ============================================================================== Execute (Create a new doc standard based on phpdoc, setup dummy pattern and execute the DogeCreateDocStandard command): + if !has('nvim') + let &runtimepath .= ',' . expand('~/.vim') + endif enew setfiletype php let b:doge_patterns = { @@ -48,7 +51,15 @@ Execute (Create a new doc standard based on phpdoc, setup dummy pattern and exec DogeCreateDocStandard phpdoc Then (Expect a file to be created with specific content): - AssertEqual expand('~/.vim/after/ftplugin/php.vim'), expand('%:p') + let b:path = '/after/ftplugin/php.vim' + if !has('nvim') + let b:path = '~/.vim' . b:path + elseif exists('*stdpath') + let b:path = '~/.config/nvim' . b:path + else + let b:path = getcwd() . b:path + endif + AssertEqual expand(b:path), expand('%:p') let b:content = join([ \ '" Preserve existing doge settings.', @@ -81,16 +92,27 @@ Then (Expect a file to be created with specific content): AssertEqual b:content, join(getline(line('^'), line('$')), "\n") unlet b:content # Remove the buffer to ensure every test will create a new doc standard file. - call delete(expand('~/.vim/after/ftplugin/php.vim')) + call delete(expand(b:path)) bdelete! Execute (Create a new doc standard for an unsupported filetype, setup dummy pattern and execute the DogeCreateDocStandard command): + if !has('nvim') + let &runtimepath .= ',' . expand('~/.vim') + endif enew setfiletype foo DogeCreateDocStandard foo Then (Expect a file to be created with specific content): - AssertEqual expand('~/.vim/after/ftplugin/foo.vim'), expand('%:p') + let b:path = '/after/ftplugin/foo.vim' + if !has('nvim') + let b:path = '~/.vim' . b:path + elseif exists('*stdpath') + let b:path = '~/.config/nvim' . b:path + else + let b:path = getcwd() . b:path + endif + AssertEqual expand(b:path), expand('%:p') let b:content = join([ \ '" Preserve existing doge settings.', @@ -123,5 +145,5 @@ Then (Expect a file to be created with specific content): AssertEqual b:content, join(getline(line('^'), line('$')), "\n") unlet b:content # Remove the buffer to ensure every test will create a new doc standard file. - call delete(expand('~/.vim/after/ftplugin/foo.vim')) + call delete(expand(b:path)) bdelete! diff --git a/test/filetypes/cpp/virtual-functions.vader b/test/filetypes/cpp/virtual-functions.vader index fe2d0887..7e8e2094 100644 --- a/test/filetypes/cpp/virtual-functions.vader +++ b/test/filetypes/cpp/virtual-functions.vader @@ -1,18 +1,101 @@ # ============================================================================== -# Virtual functions with parameters with return type. +# Virtual function declarations with parameters with return type. # ============================================================================== -# TODO: Fix tests after https://github.com/tree-sitter/tree-sitter-cpp/issues/88 -" Given cpp (virtual function with parameters with return type): -" virtual bool my_virtual_func(bool val) = 0; -" -" Do (trigger doge): -" \ -" -" Expect cpp (generated comment with @brief, @param and @return tags): -" /** -" * @brief [TODO:description] -" * -" * @param val [TODO:description] -" * @return [TODO:description] -" */ -" virtual bool my_virtual_func(bool val) = 0; +Given cpp (virtual function declarations with parameters with return type): + class Test { + virtual bool my_virtual_function(bool val); + virtual bool my_pure_virtual_function(bool val) = 0; + }; + + class Test2: public Test { + bool my_virtual_function(bool val) override; + bool my_pure_virtual_function(bool val) final; + } + +Do (trigger doge): + :2\ + \ + :9\ + \ + :19\ + \ + :26\ + \ + +Expect cpp (generated comment with @brief, @param and @return tags): + class Test { + /** + * @brief [TODO:description] + * + * @param val [TODO:description] + * @return [TODO:description] + */ + virtual bool my_virtual_function(bool val); + /** + * @brief [TODO:description] + * + * @param val [TODO:description] + * @return [TODO:description] + */ + virtual bool my_pure_virtual_function(bool val) = 0; + }; + + class Test2: public Test { + /** + * @brief [TODO:description] + * + * @param val [TODO:description] + * @return [TODO:description] + */ + bool my_virtual_function(bool val) override; + /** + * @brief [TODO:description] + * + * @param val [TODO:description] + * @return [TODO:description] + */ + bool my_pure_virtual_function(bool val) final; + } + +# ============================================================================== +# Virtual function definitions with parameters with return type. +# ============================================================================== +Given cpp (virtual function definitions with parameters with return type): + class base { + public: + bool fun_1(bool val) { cout << "base-1\n"; } + }; + + class derived : public base { + public: + bool fun_1(bool val) { cout << "derived-1\n"; } + }; + +Do (trigger doge): + :3\ + \ + :14\ + \ + +Expect cpp (generated comment with @brief, @param and @return tags): + class base { + public: + /** + * @brief [TODO:description] + * + * @param val [TODO:description] + * @return [TODO:description] + */ + bool fun_1(bool val) { cout << "base-1\n"; } + }; + + class derived : public base { + public: + /** + * @brief [TODO:description] + * + * @param val [TODO:description] + * @return [TODO:description] + */ + bool fun_1(bool val) { cout << "derived-1\n"; } + };