From 8c402d6a39dd18dafd72d42b74823484bdc43dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Fri, 19 Aug 2022 15:29:13 +0200 Subject: [PATCH] feat: remove CreateDocStandard command due to unmaintainble and unnecessary complex logic --- README.md | 11 -- autoload/doge.vim | 49 +------ autoload/doge/buffer.vim | 12 +- doc/doge.txt | 13 +- doc/tags | 1 - plugin/doge.vim | 10 -- test/autocmd-filetype.vader | 26 ---- test/commands/create-doc-standard.vader | 165 ------------------------ 8 files changed, 4 insertions(+), 283 deletions(-) delete mode 100644 test/autocmd-filetype.vader delete mode 100644 test/commands/create-doc-standard.vader diff --git a/README.md b/README.md index b5a7b266..939803ad 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,6 @@ on a function, press `d`, jump quickly through `TODO` items using - [`g:doge_comment_jump_modes`](#gdoge_comment_jump_modes) - [Commands](#commands) - [`:DogeGenerate {doc_standard}`](#dogegenerate-doc_standard) - - [`:DogeCreateDocStandard {doc_standard}`](#dogecreatedocstandard-doc_standard) - [Language-specific configuration](#language-specific-configuration) - [JavaScript](#javascript) - [PHP](#php) @@ -275,16 +274,6 @@ The numeric value should point to an index key from the The string value should point to a doc standard name listed in the `b:doge_supported_doc_standards` variable. -### `:DogeCreateDocStandard {doc_standard}` - -Command to generate a custom doc standard template. The `{doc_standard}` is a -mandatory argument which is the name of the new doc standard. If it exists, the -existing doc standard with the same name will be used as base for the custom -template. It can complete the available doc standards for the current buffer. - -For more information on how to create custom doc standards you can read -[Writing your first pattern](./CONTRIBUTING.md#writing-your-first-pattern). - # Language-specific configuration Below is a list of language-specific configuration and their default values. diff --git a/autoload/doge.vim b/autoload/doge.vim index fba36ad9..cb808bd2 100644 --- a/autoload/doge.vim +++ b/autoload/doge.vim @@ -114,9 +114,7 @@ endfunction "" " @public -" This function will be triggered on the FileType autocmd and will: -" - apply aliases -" - remove conflicting doc standards from the previous filetype. +" This function will be triggered on the FileType autocmd and will apply aliases function! doge#on_filetype_change() abort " Check if the current filetype is an alias, if so, initialize that filetype. if get(g:, 'doge_ignore_on_filetype_change', 0) == v:true @@ -133,51 +131,6 @@ function! doge#on_filetype_change() abort endif endfor endif - - " Remove conflicting doc standards from the previous filetype. - if !exists('b:doge_prev_supported_doc_standards') - \ && exists('b:doge_supported_doc_standards') - " Save the current supported doc standards - let b:doge_prev_supported_doc_standards = copy(get(b:, 'doge_supported_doc_standards', [])) - let b:doge_prev_ft = &filetype - elseif exists('b:doge_prev_supported_doc_standards') - \ && exists('b:doge_supported_doc_standards') - \ && get(b:, 'doge_prev_ft', '') != &filetype - " Remove all the doc standards from the previous filetype. - " If the current filetype is not an alias of the previous filetype then we - " will remove the doc standard. - for l:doc in get(b:, 'doge_prev_supported_doc_standards', []) - let l:is_alias = 0 - - if (has_key(g:doge_filetype_aliases, &filetype) && index(get(g:doge_filetype_aliases, &filetype, []), b:doge_prev_ft) >= 0) - \ || (has_key(g:doge_filetype_aliases, b:doge_prev_ft) && index(get(g:doge_filetype_aliases, b:doge_prev_ft, []), &filetype) >= 0) - let l:is_alias = 1 - endif - - if l:is_alias == v:false - for [l:ft, l:aliases] in items(get(g:, 'doge_filetype_aliases')) - if index(l:aliases, &filetype) >= 0 && index(l:aliases, b:doge_prev_ft) >= 0 - let l:is_alias = 1 - break - endif - endfor - endif - - if l:is_alias == v:false - let l:doc_idx = index(b:doge_supported_doc_standards, l:doc) - if l:doc_idx >= 0 && b:doge_prev_supported_doc_standards != b:doge_supported_doc_standards - call remove(b:doge_supported_doc_standards, l:doc_idx) - if has_key(get(b:, 'doge_patterns', {}), l:doc) - unlet b:doge_patterns[l:doc] - endif - endif - endif - - let b:doge_doc_standard = get(g:, 'doge_doc_standard_' . &filetype, b:doge_supported_doc_standards[0]) - endfor - let b:doge_prev_supported_doc_standards = copy(b:doge_supported_doc_standards) - let b:doge_prev_ft = &filetype - endif endfunction "" @public diff --git a/autoload/doge/buffer.vim b/autoload/doge/buffer.vim index 578be2b4..1829367c 100644 --- a/autoload/doge/buffer.vim +++ b/autoload/doge/buffer.vim @@ -17,17 +17,7 @@ endfunction " 'defaults': A list of supported doc standards that should be allowed. " Returns a list of accepted doc standards. function! doge#buffer#get_supported_doc_standards(defaults) abort - " We sort them so that we can use uniq() on it. - let l:docs = uniq(sort(extend(copy(get(b:, 'doge_supported_doc_standards', [])), a:defaults))) - - " After sorted it, we will remove the defaults and prepend the defaults so - " that we can reset the order as we defined it in the ftplugin/{ft}.vim. - for l:default in a:defaults - call remove(l:docs, index(l:docs, l:default)) - endfor - - " Prepend the defaults to the filtered docs list. - return extend(a:defaults, l:docs) + return a:defaults endfunction "" diff --git a/doc/doge.txt b/doc/doge.txt index cd4c8536..d21afeea 100644 --- a/doc/doge.txt +++ b/doc/doge.txt @@ -84,14 +84,6 @@ COMMANDS *doge-commands* The string value should point to a doc standard name listed in the `b:doge_supported_doc_standards` variable. -:DogeCreateDocStandard {doc_standard} *:DogeCreateDocStandard* - Command to generate a custom doc standard template. The `{doc_standard}` is - a mandatory argument which is the name of the new doc standard. If it - exists, the existing doc standard with the same name will be used as base - for the custom template. - - It can complete the available doc standards for the current buffer. - ============================================================================== FUNCTIONS *doge-functions* @@ -111,9 +103,8 @@ doge#command_complete() *doge#command_complete()* Return a list of supported doc standards for the current buffer. doge#on_filetype_change() *doge#on_filetype_change()* - This function will be triggered on the FileType autocmd and will: - apply aliases - remove conflicting doc standards from the previous filetype. + This function will be triggered on the FileType autocmd and will apply + aliases doge#install() *doge#install()* Install the necessary dependencies. diff --git a/doc/tags b/doc/tags index 5f20bb92..f2bea427 100644 --- a/doc/tags +++ b/doc/tags @@ -1,4 +1,3 @@ -:DogeCreateDocStandard doge.txt /*:DogeCreateDocStandard* :DogeGenerate doge.txt /*:DogeGenerate* doge doge.txt /*doge* doge#activate() doge.txt /*doge#activate()* diff --git a/plugin/doge.vim b/plugin/doge.vim index 28bb0cea..f0f0c3b4 100644 --- a/plugin/doge.vim +++ b/plugin/doge.vim @@ -203,16 +203,6 @@ endif " `b:doge_supported_doc_standards` variable. command -count -nargs=? -complete=customlist,doge#command_complete DogeGenerate call doge#generate( ? : ) -"" -" @command DogeCreateDocStandard {doc_standard} -" Command to generate a custom doc standard template. The `{doc_standard}` is a -" mandatory argument which is the name of the new doc standard. If it exists, -" the existing doc standard with the same name will be used as base for the -" custom template. -" -" It can complete the available doc standards for the current buffer. -command -nargs=1 -complete=customlist,doge#command_complete DogeCreateDocStandard call doge#pattern#custom() - augroup doge autocmd! autocmd TextChangedI * call doge#comment#update_interactive_comment_info() diff --git a/test/autocmd-filetype.vader b/test/autocmd-filetype.vader deleted file mode 100644 index db375c1d..00000000 --- a/test/autocmd-filetype.vader +++ /dev/null @@ -1,26 +0,0 @@ -# ============================================================================== -# Switch from PHP to JavaScript and make sure doc standards of PHP get removed. -# ============================================================================== - -Execute (switch from PHP to JavaScript): - setfiletype php - AssertEqual exists('b:doge_prev_supported_doc_standards'), 1 - AssertEqual has_key(b:doge_patterns, 'phpdoc'), 1 - AssertEqual has_key(b:doge_patterns, 'jsdoc'), 0 - - Assert index(b:doge_supported_doc_standards, 'phpdoc') >= 0 - Assert index(b:doge_supported_doc_standards, 'jsdoc') < 0 - - Assert index(b:doge_prev_supported_doc_standards, 'phpdoc') >= 0 - Assert index(b:doge_prev_supported_doc_standards, 'jsdoc') < 0 - -# Change to JavaScript and make sure the phpdoc gets removed. - setfiletype javascript - AssertEqual 0, has_key(b:doge_patterns, 'phpdoc') - AssertEqual 1, has_key(b:doge_patterns, 'jsdoc') - - Assert index(b:doge_supported_doc_standards, 'phpdoc') < 0 - Assert index(b:doge_supported_doc_standards, 'jsdoc') >= 0 - - Assert index(b:doge_prev_supported_doc_standards, 'phpdoc') < 0 - Assert index(b:doge_prev_supported_doc_standards, 'jsdoc') >= 0 diff --git a/test/commands/create-doc-standard.vader b/test/commands/create-doc-standard.vader deleted file mode 100644 index 68367c1e..00000000 --- a/test/commands/create-doc-standard.vader +++ /dev/null @@ -1,165 +0,0 @@ -# ============================================================================== -# -# Test the DogeCreateDocStandard command -# -# ============================================================================== - -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 = { - \ 'phpdoc': [ - \ { - \ 'nodeTypes': [ - \ 'property_declaration', - \ ], - \ 'typeParameters': { - \ 'format': '@param {name} !description', - \ }, - \ 'template': [ - \ '/**', - \ ' * @var {type|!type}', - \ ' */', - \ ], - \ }, - \ { - \ 'nodeTypes': [ - \ 'method_declaration', - \ 'function_definition', - \ ], - \ 'parameters': { - \ 'format': '@param {type|!type} {name}%(default| (optional))% !description', - \ }, - \ 'exceptions': { - \ 'format': '@param {name} !description', - \ }, - \ 'template': [ - \ '/**', - \ ' * !description', - \ '%(parameters| *)%', - \ '%(parameters| * {parameters})%', - \ '%(isNoConstructorMethod| *)%', - \ '%(isNoConstructorMethod| * @return {returnType|!type} !description)%', - \ ' */', - \ ], - \ }, - \ ], - \} - DogeCreateDocStandard phpdoc - -Then (Expect a file to be created with specific content): - let b:path = '' - for b:p in ['~/.vim', '~/vimfiles'] - let b:p = expand(b:p) - if match(&runtimepath, b:p) >= 0 - let b:path = b:p - break - endif - endfor - if empty(b:path) - if exists('*stdpath') - let b:path = stdpath('config') - else - let b:path = getcwd() - endif - endif - let b:path .= '/after/ftplugin/php.vim' - AssertEqual expand(b:path), expand('%:p') - - let b:content = join([ - \ '" Preserve existing doge settings.', - \ "let b:doge_patterns = get(b:, 'doge_patterns', {})", - \ "let b:doge_supported_doc_standards = get(b:, 'doge_supported_doc_standards', [])", - \ "if index(b:doge_supported_doc_standards, 'phpdoc_custom') < 0", - \ " call add(b:doge_supported_doc_standards, 'phpdoc_custom')", - \ "endif", - \ "", - \ '" Set the new doc standard as default.', - \ "let b:doge_doc_standard = 'phpdoc_custom'", - \ "", - \ '" Ensure we do not overwrite an existing doc standard.', - \ "if !has_key(b:doge_patterns, 'phpdoc_custom')", - \ " let b:doge_patterns['phpdoc_custom'] = [", - \ " \\ {", - \ " \\ 'nodeTypes': ['NODE_TYPE_A', 'NODE_TYPE_B'],", - \ " \\ 'parameters': {", - \ " \\ 'format': '@param {name} !description',", - \ " \\ },", - \ " \\ 'template': [", - \ " \\ '/**',", - \ " \\ ' * @var {type|!type}',", - \ " \\ ' */',", - \ " \\ ],", - \ " \\ },", - \ " \\]", - \ "endif", - \], "\n") - 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(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): - let b:path = '' - for b:p in ['~/.vim', '~/vimfiles'] - let b:p = expand(b:p) - if match(&runtimepath, b:p) >= 0 - let b:path = b:p - break - endif - endfor - if empty(b:path) - if exists('*stdpath') - let b:path = stdpath('config') - else - let b:path = getcwd() - endif - endif - let b:path .= '/after/ftplugin/foo.vim' - AssertEqual expand(b:path), expand('%:p') - - let b:content = join([ - \ '" Preserve existing doge settings.', - \ "let b:doge_patterns = get(b:, 'doge_patterns', {})", - \ "let b:doge_supported_doc_standards = get(b:, 'doge_supported_doc_standards', [])", - \ "if index(b:doge_supported_doc_standards, 'foo') < 0", - \ " call add(b:doge_supported_doc_standards, 'foo')", - \ "endif", - \ "", - \ "let b:doge_parser = 'PARSER_NAME_HERE'", - \ "let b:doge_insert = 'above'", - \ "", - \ '" Set the new doc standard as default.', - \ "let b:doge_doc_standard = 'foo'", - \ "", - \ '" Ensure we do not overwrite an existing doc standard.', - \ "if !has_key(b:doge_patterns, 'foo')", - \ " let b:doge_patterns['foo'] = [", - \ " \\ {", - \ " \\ 'nodeTypes': ['NODE_TYPE_A', 'NODE_TYPE_B'],", - \ " \\ 'parameters': {", - \ " \\ 'format': '@param {name} !description',", - \ " \\ },", - \ " \\ 'template': [", - \ " \\ ],", - \ " \\ },", - \ " \\]", - \ "endif", - \], "\n") - 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(b:path)) - bdelete!