From e7a379cec1fad748521dcb2efe2a8f90fc9df932 Mon Sep 17 00:00:00 2001 From: Gerard Roche Date: Sat, 30 Jan 2016 19:24:28 +0000 Subject: [PATCH 1/2] Fix settings; refactor the way settings are loaded * Fixes #313 * Fixes #334 * Fixes #338 * Fixes #408 * Fixes #400 * Fixes #360 * Fixes #397 --- Default.sublime-keymap | 12 +- ...e-settings => Preferences.sublime-settings | 50 +++---- README.md | 74 ++++------ jsdocs.py | 128 ++++++++++++------ test_runner.py | 36 ++--- tests/Default.sublime-keymap | 4 +- 6 files changed, 167 insertions(+), 137 deletions(-) rename Base File.sublime-settings => Preferences.sublime-settings (83%) diff --git a/Default.sublime-keymap b/Default.sublime-keymap index 8db9dc9..b39073e 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -79,7 +79,7 @@ { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n${TM_CURRENT_LINE/^\\s*((?:#|\\/\\/[\\/!]?)\\s*).*/$1/}"}, "context": [ { "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true }, - { "key": "setting.jsdocs_extend_double_slash", "operator": "equal", "operand": true, "match_all": true }, + { "key": "setting.docblockr.extend_double_slash", "operator": "equal", "operand": true, "match_all": true }, { "key": "selector", "operator": "equal", "operand": "comment.line", "match_all": true }, { "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true }, { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\\/\\/[\\/!]?|#)", "match_all": true } @@ -89,7 +89,7 @@ { "keys": ["keypad_enter"], "command": "insert_snippet", "args": {"contents": "\n${TM_CURRENT_LINE/^\\s*((?:#|\\/\\/[\\/!]?)\\s*).*$/$1/}"}, "context": [ { "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true }, - { "key": "setting.jsdocs_extend_double_slash", "operator": "equal", "operand": true, "match_all": true }, + { "key": "setting.docblockr.extend_double_slash", "operator": "equal", "operand": true, "match_all": true }, { "key": "selector", "operator": "equal", "operand": "comment.line", "match_all": true }, { "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true }, { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*\\/\\/[\\/!]?", "match_all": true } @@ -150,7 +150,7 @@ { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true }, { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*\\/\\*{2}$", "match_all": true }, - { "key": "setting.jsdocs_quick_open_inline", "operator": "equal", "operand": true, "match_all": true} + { "key": "setting.docblockr.quick_open_inline", "operator": "equal", "operand": true, "match_all": true} ] }, // Open an inline docblock (/** */) @@ -191,7 +191,7 @@ // indent to align with the previous line { "keys": ["tab"], "command": "jsdocs_indent", "context": [ - { "key": "setting.jsdocs_deep_indent", "operator": "equal", "operand": true, "match_all": true }, + { "key": "setting.docblockr.deep_indent", "operator": "equal", "operand": true, "match_all": true }, { "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*\\*\\s*$", "match_all": true }, @@ -201,14 +201,14 @@ // decorate a double-slash comment { "keys": ["ctrl+enter"], "command": "jsdocs_decorate", "context": [ - { "key": "setting.jsdocs_decorate", "operator": "equal", "operand": true, "match_all": true }, + { "key": "setting.docblockr.decorate", "operator": "equal", "operand": true, "match_all": true }, { "key": "selector", "operator": "equal", "operand": "comment.line.double-slash", "match_all": true } ] }, // decorate a double-slash comment { "keys": ["ctrl+keypad_enter"], "command": "jsdocs_decorate", "context": [ - { "key": "setting.jsdocs_decorate", "operator": "equal", "operand": true, "match_all": true }, + { "key": "setting.docblockr.decorate", "operator": "equal", "operand": true, "match_all": true }, { "key": "selector", "operator": "equal", "operand": "comment.line.double-slash", "match_all": true } ] }, diff --git a/Base File.sublime-settings b/Preferences.sublime-settings similarity index 83% rename from Base File.sublime-settings rename to Preferences.sublime-settings index bfc179e..33534ee 100644 --- a/Base File.sublime-settings +++ b/Preferences.sublime-settings @@ -2,14 +2,14 @@ // If true, when in a docblock, pressing tab after a @tag line (like @param, @return) // will indent to the description. This is useful if you are writing a long description // and want that block of text to stay aligned. - "jsdocs_deep_indent": true, + "docblockr.deep_indent": true, // If true, then pressing enter while in a double-slash comment (like this one) // will automatically add two slashes to the next line as well - "jsdocs_extend_double_slash": true, + "docblockr.extend_double_slash": true, // the number of spaces to add after the leading * - "jsdocs_indentation_spaces": 1, + "docblockr.indentation_spaces": 1, // The number of spaces to add after the leading * in lines under the first line of each // paragraph. This is only used together with automatic line wrapping. For example, a value @@ -24,7 +24,7 @@ // * massa, sit amet adipiscing dolor. // * @return {[Type]} // */ - "jsdocs_indentation_spaces_same_para": 1, + "docblockr.indentation_spaces_same_para": 1, // whether the words following the @tags should align. // Possible values are 'no', 'shallow', 'deep' @@ -39,34 +39,34 @@ // @param {MyCustomClass} myVariable desc1 // @return {String} foo desc2 // @property {Number} blahblah desc3 - "jsdocs_align_tags": "deep", + "docblockr.align_tags": "deep", // Any additional boilerplate tags which should be added to each block. Should be an array of strings. // Note that this only applies when a docblock is opened directly preceding a function. // Tab points can be added by using snippet syntax, eg: ${1:default text} - "jsdocs_extra_tags": [], + "docblockr.extra_tags": [], // If extra tags are defined, by default they go between the description and the param/return tags. If this is set to // true, the extra tags are placed at the very end. - "jsdocs_extra_tags_go_after": false, + "docblockr.extra_tags_go_after": false, // A map to determine the value of variables, should hungarian notation (or similar) be in use - "jsdocs_notation_map": [], + "docblockr.notation_map": [], // Since there seems to be no agreed standard for "@return" or "@returns", use this setting to rename it as you wish. - "jsdocs_return_tag": "@return", + "docblockr.return_tag": "@return", // Add a '[function_name description]' for the function block - "jsdocs_function_description": true, + "docblockr.function_description": true, // Add a '[description]' placeholder for the return tag? - "jsdocs_return_description": true, + "docblockr.return_description": true, // Add a '[description]' placeholder for the param tag? - "jsdocs_param_description": true, + "docblockr.param_description": true, // Add a name of parameter in param tag? - "jsdocs_param_name": true, + "docblockr.param_name": true, // Whether there should be blank lines added between the description line, and between tags of different types. // Possible values are true, false, or "after_description". @@ -91,11 +91,11 @@ // * @param {Number} bar // * @return {[Type]} // */ - "jsdocs_spacer_between_sections": false, + "docblockr.spacer_between_sections": false, // Whether each section should be indented to the same level, or indent each one individually. // (When true, the @param section will lose the extra space immediately after each '@param'). - "jsdocs_per_section_indent": false, + "docblockr.per_section_indent": false, // Minimum spaces between cols (default is 1). For example, a value // of 2 might look like this: @@ -108,32 +108,32 @@ // * // * @return {[Type]} description // */ - "jsdocs_min_spaces_between_columns": 1, + "docblockr.min_spaces_between_columns": 1, // indicates whether the @method tag should be added automatically - "jsdocs_autoadd_method_tag": false, + "docblockr.autoadd_method_tag": false, // If set to true, DocBlockr won't parse any code, providing no default templates. All other functions work as normal. - "jsdocs_simple_mode": false, + "docblockr.simple_mode": false, // If set to true, primitives such as "Number" and "String" will be documented as "number" and "string". - "jsdocs_lower_case_primitives": false, + "docblockr.lower_case_primitives": false, // If set to true, primitives such as "boolean" and "integer" will be shortened to "bool" and "int". - "jsdocs_short_primitives": false, + "docblockr.short_primitives": false, // This property affects the default tag added to `var` declarations in Javascript/Coffeescript. If `false`, the // default is used ("var"), otherwise it can be set to any String, eg: "property" - "jsdocs_override_js_var": false, + "docblockr.override_js_var": false, // If set to true, an extra line break is added after the end of a docblock to separate it from the code. - "jsdocs_newline_after_block": false, + "docblockr.newline_after_block": false, // If set to true, Ctrl+Enter while in a single line comment will 'decorate' the comment. - "jsdocs_decorate": true, + "docblockr.decorate": true, // If set to true, typing /** will open an inline docblock - "jsdocs_quick_open_inline": true, + "docblockr.quick_open_inline": true, - "jsdocs_development_mode": false + "docblockr.development_mode": false } diff --git a/README.md b/README.md index 238039d..79680b4 100644 --- a/README.md +++ b/README.md @@ -24,27 +24,7 @@ the pull request back to that branch. ## Changelog -- **v2.14.1**, *17 Aug 2015* - - Fix deindentation bug with reparsing doc blocks -- **v2.14.0**, *15 Jun 2015* - - Adds `jsdocs_function_description` option (thanks to [Gerard Roche](https://github.com/gerardroche)) - - Better handling of parser errors (thanks to Gerard Roche) -- **v2.13.3**, *4 Jun 2015* - - PHP array shorthand is identified correctly (thanks to [Gerard Roche](https://github.com/gerardroche)) - - Decorating comments when using tabs for indentation works better (thanks to [Jack Cherng](https://github.com/jfcherng)) -- **v2.13.2**, *30 Mar 2015* - - Updated PHPDoc autocompletions to align with the new spec (thanks to [Gerard Roche](https://github.com/gerardroche)) - - Properly handle the case when commas appear inside a type name in Java - - Added link to README in the preferences menu -- **v2.13.1**, *29 Mar 2015* - - Adds support for Apex language (thanks @michacom) - - Fixes identifying multidimensional arrays in C/C++ - - Fixes reformatting and reparsing docblocks in Java - - Adds options to disable: - - opening an inline docblock with space (`jsdocs_quick_open_inline`) - - inline comment decoration (`jsdocs_decorate`) - -Older history can be found in [the history file][history]. +See [the history file][history]. ## Usage @@ -100,7 +80,7 @@ DocBlockr will also try to determine the type of the variable from its name. Var ```js { - "jsdocs_notation_map": [ + "docblockr.notation_map": [ { "prefix": "b", /* a prefix, matches only if followed by an underscore or A-Z */ "type": "bool" /* translates to "Boolean" in javascript, "bool" in PHP */ @@ -152,7 +132,7 @@ If you write a double-slash comment and then press `Ctrl+Enter`, DocBlockr will // Foo bar baz // ///////////////// -This can be disabled by changing the `jsdocs_decorate` setting to `false`. +This can be disabled by changing the `docblockr.decorate` setting to `false`. ### Reparsing a DocBlock @@ -182,21 +162,19 @@ Finally, typing `@` inside a docblock will show a completion list for all tags s You can access the configuration settings by selecting `Preferences -> Package Settings -> DocBlockr`. -*The `jsdocs_*` prefix is a legacy from days gone by...* +- `docblockr.indentation_spaces` *(Number)* The number of spaces to indent after the leading asterisk. -- `jsdocs_indentation_spaces` *(Number)* The number of spaces to indent after the leading asterisk. - - // jsdocs_indentation_spaces = 1 + // docblockr.indentation_spaces = 1 /** * foo */ - // jsdocs_indentation_spaces = 5 + // docblockr.indentation_spaces = 5 /** * foo */ -- `jsdocs_align_tags` *(String)* Whether the words following the tags should align. Possible values are `'no'`, `'shallow'` and `'deep'` +- `docblockr.align_tags` *(String)* Whether the words following the tags should align. Possible values are `'no'`, `'shallow'` and `'deep'` > For backwards compatibility, `false` is equivalent to `'no'`, `true` is equivalent to `'shallow'` @@ -213,9 +191,9 @@ You can access the configuration settings by selecting `Preferences -> Package S @property {Number} blahblah desc3 -- `jsdocs_extra_tags` *(Array.String)* An array of strings, each representing extra boilerplate comments to add to *functions*. These can also include arbitrary text (not just tags). +- `docblockr.extra_tags` *(Array.String)* An array of strings, each representing extra boilerplate comments to add to *functions*. These can also include arbitrary text (not just tags). - // jsdocs_extra_tags = ['This is a cool function', '@author nickf', '@version ${1:[version]}'] + // docblockr.extra_tags = ['This is a cool function', '@author nickf', '@version ${1:[version]}'] /**<> function foo (x) {} @@ -231,7 +209,7 @@ You can access the configuration settings by selecting `Preferences -> Package S Basic variable substitution is supported here for the variables `date` and `datetime`, wrapped in double curly brackets. - // jsdocs_extra_tags = ['@date {{date}}', '@anotherdate {{datetime}}'] + // docblockr.extra_tags = ['@date {{date}}', '@anotherdate {{datetime}}'] /**<> function foo() {} @@ -242,37 +220,37 @@ You can access the configuration settings by selecting `Preferences -> Package S * @return {[type]} */ -- `jsdocs_extra_tags_go_after` *(Boolean)* If true, the extra tags are placed at the end of the block (after param/return). Default: `false` +- `docblockr.extra_tags_go_after` *(Boolean)* If true, the extra tags are placed at the end of the block (after param/return). Default: `false` -- `jsdocs_extend_double_slash` *(Boolean)* Whether double-slash comments should be extended. An example of this feature is described above. Default: `true` +- `docblockr.extend_double_slash` *(Boolean)* Whether double-slash comments should be extended. An example of this feature is described above. Default: `true` -- `jsdocs_deep_indent` *(Boolean)* Whether pressing tab at the start of a line in docblock should indent to match the previous line's description field. An example of this feature is described above. Default: `true` +- `docblockr.deep_indent` *(Boolean)* Whether pressing tab at the start of a line in docblock should indent to match the previous line's description field. An example of this feature is described above. Default: `true` -- `jsdocs_notation_map` *(Array)* An array of notation objects. Each notation object must define either a `prefix` OR a `regex` property, and a `type` property. +- `docblockr.notation_map` *(Array)* An array of notation objects. Each notation object must define either a `prefix` OR a `regex` property, and a `type` property. -- `jsdocs_return_tag` *(String)* The text which should be used for a `@return` tag. By default, `@return` is used, however this can be changed to `@returns` if you use that style. +- `docblockr.return_tag` *(String)* The text which should be used for a `@return` tag. By default, `@return` is used, however this can be changed to `@returns` if you use that style. -- `jsdocs_spacer_between_sections` *(Boolean|String)* If true, then extra blank lines are inserted between the sections of the docblock. If set to `"after_description"` then a spacer will only be added between the description and the first tag. Default: `false`. +- `docblockr.spacer_between_sections` *(Boolean|String)* If true, then extra blank lines are inserted between the sections of the docblock. If set to `"after_description"` then a spacer will only be added between the description and the first tag. Default: `false`. -- `jsdocs_indentation_spaces_same_para` *(Number)* Described above in the *Reformatting paragraphs* section. Default: `1` +- `docblockr.indentation_spaces_same_para` *(Number)* Described above in the *Reformatting paragraphs* section. Default: `1` -- `jsdocs_autoadd_method_tag` *(Boolean)* Add a `@method` tag to docblocks of functions. Default: `false` +- `docblockr.autoadd_method_tag` *(Boolean)* Add a `@method` tag to docblocks of functions. Default: `false` -- `jsdocs_simple_mode` *(Boolean)* If true, DocBlockr won't add a template when creating a doc block before a function or variable. Useful if you don't want to write Javadoc-style, but still want your editor to help when writing block comments. Default: `false` +- `docblockr.simple_mode` *(Boolean)* If true, DocBlockr won't add a template when creating a doc block before a function or variable. Useful if you don't want to write Javadoc-style, but still want your editor to help when writing block comments. Default: `false` -- `jsdocs_lower_case_primitives` *(Boolean)* If true, primitive data types are added in lower case, eg "number" instead of "Number". Default: `false` +- `docblockr.lower_case_primitives` *(Boolean)* If true, primitive data types are added in lower case, eg "number" instead of "Number". Default: `false` -- `jsdocs_short_primitives` *(Boolean)* If true, the primitives `Boolean` and `Integer` are shortened to `Bool` and `Int`. Default: `false` +- `docblockr.short_primitives` *(Boolean)* If true, the primitives `Boolean` and `Integer` are shortened to `Bool` and `Int`. Default: `false` -- `jsdocs_newline_after_block` *(Boolean)* If true, an extra line break is added after the end of a docblock to separate it from the code. Default `false` +- `docblockr.newline_after_block` *(Boolean)* If true, an extra line break is added after the end of a docblock to separate it from the code. Default `false` -- `jsdocs_param_name` *(Boolean)* If true, the name of a function parameter is added to the template. If false, it is omitted. Default: `true` +- `docblockr.param_name` *(Boolean)* If true, the name of a function parameter is added to the template. If false, it is omitted. Default: `true` -- `jsdocs_decorate` *(Boolean)* If false, disable decoration of single line comments with Ctrl+Enter. Default: `true` +- `docblockr.decorate` *(Boolean)* If false, disable decoration of single line comments with Ctrl+Enter. Default: `true` -- `jsdocs_quick_open_inline` *(Boolean)* If true, an inline docblock will be opened when pressing Space after an opener (`/**`). When set to `false`, these can be opened by pressing Shift+Enter. Default: `true` +- `docblockr.quick_open_inline` *(Boolean)* If true, an inline docblock will be opened when pressing Space after an opener (`/**`). When set to `false`, these can be opened by pressing Shift+Enter. Default: `true` -- `jsdocs_function_description` *(Boolean)* If true, a 'description' line will be added for functions. Default: `true` +- `docblockr.function_description` *(Boolean)* If true, a 'description' line will be added for functions. Default: `true` ## Contributors diff --git a/jsdocs.py b/jsdocs.py index 3f81588..c42353b 100644 --- a/jsdocs.py +++ b/jsdocs.py @@ -13,6 +13,54 @@ import time import imp from functools import reduce +import sys + +def plugin_loaded(): + migrate_old_settings() + +def migrate_old_settings(): + view = sublime.active_window().active_view() + if view: + if view.settings().has('docblockr.old_settings_migrated'): + return # settings have already been migrated + + print('') + print('[docblockr] migrating old docblockr settings') + print('') + + import os + + old_settings_file = os.path.join(sublime.packages_path(), 'User', 'Base File.sublime-settings') + if not os.path.isfile(old_settings_file): + return + + old_settings_file_content = None + with open(old_settings_file) as f: + old_settings_file_content = f.read() + + if not old_settings_file_content: + return + + decoded_old_settings = sublime.decode_value(old_settings_file_content) + + existing_settings = [] + for k, v in decoded_old_settings.items(): + if k[:7] == 'jsdocs_': + existing_settings.append(k) + + preferences = sublime.load_settings('Preferences.sublime-settings') + + for old_key in existing_settings: + preferences.set('docblockr.' + old_key[7:], decoded_old_settings[old_key]) + + preferences.set('docblockr.old_settings_migrated', True) + sublime.save_settings('Preferences.sublime-settings') + + for k in existing_settings: + del decoded_old_settings[k] + + if len(decoded_old_settings) <= 0: + os.remove(old_settings_file) def read_line(view, point): if (point >= view.size()): @@ -177,10 +225,10 @@ def initialize(self, v, inline=False): # drop trailing '*/' self.trailingString = escape(re.sub('\\s*\\*\\/\\s*$', '', self.trailingString)) - self.indentSpaces = " " * max(0, self.settings.get("jsdocs_indentation_spaces", 1)) + self.indentSpaces = " " * max(0, self.settings.get("docblockr.indentation_spaces", 1)) self.prefix = "*" - settingsAlignTags = self.settings.get("jsdocs_align_tags", 'deep') + settingsAlignTags = self.settings.get("docblockr.align_tags", 'deep') self.deepAlignTags = settingsAlignTags == 'deep' self.shallowAlignTags = settingsAlignTags in ('shallow', True) @@ -214,7 +262,7 @@ def generateSnippet(self, out, inline=False): else: return " $0 */" else: - return self.createSnippet(out) + ('\n' if self.settings.get('jsdocs_newline_after_block') else '') + return self.createSnippet(out) + ('\n' if self.settings.get('docblockr.newline_after_block') else '') def alignTags(self, out): def outputWidth(str): @@ -228,8 +276,8 @@ def outputWidth(str): widths = [] # Grab the return tag if required. - if self.settings.get('jsdocs_per_section_indent'): - returnTag = self.settings.get('jsdocs_return_tag') or '@return' + if self.settings.get('docblockr.per_section_indent'): + returnTag = self.settings.get('docblockr.return_tag') or '@return' else: returnTag = False @@ -258,7 +306,7 @@ def outputWidth(str): maxWidths = dict(enumerate(maxWidths)) # Minimum spaces between line columns - minColSpaces = self.settings.get('jsdocs_min_spaces_between_columns', 1) + minColSpaces = self.settings.get('docblockr.min_spaces_between_columns', 1) for index, line in enumerate(out): # format the spacing of columns, but ignore the author tag. (See #197) @@ -308,18 +356,18 @@ def createSnippet(self, out): snippet = "" closer = self.parser.settings['commentCloser'] if out: - if self.settings.get('jsdocs_spacer_between_sections') == True: + if self.settings.get('docblockr.spacer_between_sections') == True: lastTag = None for idx, line in enumerate(out): res = re.match("^\\s*@([a-zA-Z]+)", line) if res and (lastTag != res.group(1)): - if self.settings.get('jsdocs_function_description') == False: + if self.settings.get('docblockr.function_description') == False: if lastTag != None: out.insert(idx, "") else: out.insert(idx, "") lastTag = res.group(1) - elif self.settings.get('jsdocs_spacer_between_sections') == 'after_description' and self.settings.get('jsdocs_function_description'): + elif self.settings.get('docblockr.spacer_between_sections') == 'after_description' and self.settings.get('docblockr.function_description'): lastLineIsTag = False for idx, line in enumerate(out): res = re.match("^\\s*@([a-zA-Z]+)", line) @@ -354,7 +402,7 @@ def getNameOverride(self): return self.nameOverride def parse(self, line): - if self.viewSettings.get('jsdocs_simple_mode'): + if self.viewSettings.get('docblockr.simple_mode'): return None try: @@ -413,13 +461,13 @@ def formatFunction(self, name, args, retval, options={}): out.append('@private') return out - extraTagAfter = self.viewSettings.get("jsdocs_extra_tags_go_after") or False + extraTagAfter = self.viewSettings.get("docblockr.extra_tags_go_after") or False description = self.getNameOverride() or ('[%s%sdescription]' % (escape(name), ' ' if name else '')) - if self.viewSettings.get('jsdocs_function_description'): + if self.viewSettings.get('docblockr.function_description'): out.append("${1:%s}" % description) - if (self.viewSettings.get("jsdocs_autoadd_method_tag") is True): + if (self.viewSettings.get("docblockr.autoadd_method_tag") is True): out.append("@%s %s" % ( "method", escape(name) @@ -436,12 +484,12 @@ def formatFunction(self, name, args, retval, options={}): typeInfo = self.getTypeInfo(argType, argName) format_str = "@param %s%s" - if (self.viewSettings.get('jsdocs_param_description')): + if (self.viewSettings.get('docblockr.param_description')): format_str += " ${1:[description]}" out.append(format_str % ( typeInfo, - escape(argName) if self.viewSettings.get('jsdocs_param_name') else '' + escape(argName) if self.viewSettings.get('docblockr.param_name') else '' )) # return value type might be already available in some languages but @@ -456,17 +504,17 @@ def formatFunction(self, name, args, retval, options={}): "}" if self.settings['curlyTypes'] else "" ) format_args = [ - self.viewSettings.get('jsdocs_return_tag') or '@return', + self.viewSettings.get('docblockr.return_tag') or '@return', typeInfo ] - if (self.viewSettings.get('jsdocs_return_description')): + if (self.viewSettings.get('docblockr.return_description')): format_str = "%s%s %s${1:[description]}" third_arg = "" # the extra space here is so that the description will align with the param description - if args and self.viewSettings.get('jsdocs_align_tags') == 'deep': - if not self.viewSettings.get('jsdocs_per_section_indent'): + if args and self.viewSettings.get('docblockr.align_tags') == 'deep': + if not self.viewSettings.get('docblockr.per_section_indent'): third_arg = " " format_args.append(third_arg) @@ -524,7 +572,7 @@ def getArgName(self, arg): return arg def addExtraTags(self, out): - extraTags = self.viewSettings.get('jsdocs_extra_tags', []) + extraTags = self.viewSettings.get('docblockr.extra_tags', []) if (len(extraTags) > 0): out.extend(extraTags) @@ -553,7 +601,7 @@ def checkMatch(rule): elif 'regex' in rule: return re.search(rule['regex'], name) - return list(filter(checkMatch, self.viewSettings.get('jsdocs_notation_map', []))) + return list(filter(checkMatch, self.viewSettings.get('docblockr.notation_map', []))) def getDefinition(self, view, pos): """ @@ -605,7 +653,7 @@ def setupSettings(self): # curly brackets around the type information "curlyTypes": True, 'typeInfo': True, - "typeTag": self.viewSettings.get('jsdocs_override_js_var') or "type", + "typeTag": self.viewSettings.get('docblockr.override_js_var') or "type", # technically, they can contain all sorts of unicode, but w/e "varIdentifier": identifier, "fnIdentifier": identifier, @@ -717,19 +765,19 @@ def getMatchingNotations(self, name): out = super(JsdocsJavascript, self).getMatchingNotations(name) if name and name[0] == '*': # if '@returns' is preferred, then also use '@yields'. Otherwise, '@return' and '@yield' - yieldTag = '@yield' + ('s' if self.viewSettings.get('jsdocs_return_tag', '_')[-1] == 's' else '') - description = ' ${1:[description]}' if self.viewSettings.get('jsdocs_return_description', True) else '' + yieldTag = '@yield' + ('s' if self.viewSettings.get('docblockr.return_tag', '_')[-1] == 's' else '') + description = ' ${1:[description]}' if self.viewSettings.get('docblockr.return_description', True) else '' out.append({ 'tags': [ '%s {${1:[type]}}%s%s' % ( yieldTag, - ' ' if self.viewSettings.get('jsdocs_align_tags') == 'deep' and not self.viewSettings.get('jsdocs_per_section_indent') else '', + ' ' if self.viewSettings.get('docblockr.align_tags') == 'deep' and not self.viewSettings.get('docblockr.per_section_indent') else '', description )]}) return out def guessTypeFromValue(self, val): - lowerPrimitives = self.viewSettings.get('jsdocs_lower_case_primitives') or False - shortPrimitives = self.viewSettings.get('jsdocs_short_primitives') or False + lowerPrimitives = self.viewSettings.get('docblockr.lower_case_primitives') or False + shortPrimitives = self.viewSettings.get('docblockr.short_primitives') or False if is_numeric(val): return "number" if lowerPrimitives else "Number" if val[0] == '"' or val[0] == "'": @@ -753,7 +801,7 @@ def guessTypeFromValue(self, val): class JsdocsPHP(JsdocsParser): def setupSettings(self): - shortPrimitives = self.viewSettings.get('jsdocs_short_primitives') or False + shortPrimitives = self.viewSettings.get('docblockr.short_primitives') or False nameToken = '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*' self.settings = { # curly brackets around the type information @@ -851,7 +899,7 @@ def parseVar(self, line): return None def guessTypeFromValue(self, val): - shortPrimitives = self.viewSettings.get('jsdocs_short_primitives') or False + shortPrimitives = self.viewSettings.get('docblockr.short_primitives') or False if is_numeric(val): return "float" if '.' in val else 'int' if shortPrimitives else 'integer' if val[0] == '"' or val[0] == "'": @@ -868,7 +916,7 @@ def guessTypeFromValue(self, val): return None def getFunctionReturnType(self, name, retval): - shortPrimitives = self.viewSettings.get('jsdocs_short_primitives') or False + shortPrimitives = self.viewSettings.get('docblockr.short_primitives') or False if (name[:2] == '__'): if name in ('__construct', '__destruct', '__set', '__unset', '__wakeup'): return None @@ -942,7 +990,7 @@ def setupSettings(self): self.settings = { # curly brackets around the type information 'curlyTypes': True, - 'typeTag': self.viewSettings.get('jsdocs_override_js_var') or "type", + 'typeTag': self.viewSettings.get('docblockr.override_js_var') or "type", 'typeInfo': True, # technically, they can contain all sorts of unicode, but w/e 'varIdentifier': identifier, @@ -987,7 +1035,7 @@ def parseVar(self, line): return (res.group('name'), res.group('val').strip()) def guessTypeFromValue(self, val): - lowerPrimitives = self.viewSettings.get('jsdocs_lower_case_primitives') or False + lowerPrimitives = self.viewSettings.get('docblockr.lower_case_primitives') or False if is_numeric(val): return "number" if lowerPrimitives else "Number" if val[0] == '"' or val[0] == "'": @@ -1419,7 +1467,7 @@ def run(self, edit): v = self.view lineRegion = v.line(v.sel()[0]) line = v.substr(lineRegion) - spaces = max(0, v.settings().get("jsdocs_indentation_spaces", 1)) + spaces = max(0, v.settings().get("docblockr.indentation_spaces", 1)) v.replace(edit, lineRegion, re.sub("^(\\s*\\*)\\s*$", "\\1\n\\1" + (" " * spaces), line)) @@ -1437,11 +1485,11 @@ def run(self, edit): tabSize = settings.get('tab_size') wrapLength = rulers[0] if (len(rulers) > 0) else 80 - numIndentSpaces = max(0, settings.get("jsdocs_indentation_spaces", 1)) + numIndentSpaces = max(0, settings.get("docblockr.indentation_spaces", 1)) indentSpaces = " " * numIndentSpaces - indentSpacesSamePara = " " * max(0, settings.get("jsdocs_indentation_spaces_same_para", numIndentSpaces)) - spacerBetweenSections = settings.get("jsdocs_spacer_between_sections") == True - spacerBetweenDescriptionAndTags = settings.get("jsdocs_spacer_between_sections") == "after_description" + indentSpacesSamePara = " " * max(0, settings.get("docblockr.indentation_spaces_same_para", numIndentSpaces)) + spacerBetweenSections = settings.get("docblockr.spacer_between_sections") == True + spacerBetweenDescriptionAndTags = settings.get("docblockr.spacer_between_sections") == "after_description" dbRegion = getDocBlockRegion(v, v.sel()[0].begin()) @@ -1597,7 +1645,7 @@ def getFunctionReturnType(self, name, retval): return retval if retval != 'void' else None def guessTypeFromValue(self, val): - lowerPrimitives = self.viewSettings.get('jsdocs_lower_case_primitives') or False + lowerPrimitives = self.viewSettings.get('docblockr.lower_case_primitives') or False if is_numeric(val): return "number" if lowerPrimitives else "Number" if val[0] == '"' or val[0] == "'": @@ -1614,3 +1662,7 @@ def guessTypeFromValue(self, val): res = re.search('new (' + self.settings['fnIdentifier'] + ')', val) return res and res.group(1) or None return None + +# ST2 compat +if sys.version_info < (3,): + plugin_loaded() diff --git a/test_runner.py b/test_runner.py index f64a07a..b0182d4 100644 --- a/test_runner.py +++ b/test_runner.py @@ -23,13 +23,13 @@ def setUp(self): # TODO there's probably a better way to initialise the testcase default settings settings = self.view.settings() settings.set('auto_indent', False) - settings.set('jsdocs_lower_case_primitives', False) - settings.set('jsdocs_param_description', True) - settings.set('jsdocs_per_section_indent', False) - settings.set('jsdocs_return_description', True) - settings.set('jsdocs_short_primitives', False) - settings.set('jsdocs_spacer_between_sections', False) - settings.set('jsdocs_function_description', True) + settings.set('docblockr.lower_case_primitives', False) + settings.set('docblockr.param_description', True) + settings.set('docblockr.per_section_indent', False) + settings.set('docblockr.return_description', True) + settings.set('docblockr.short_primitives', False) + settings.set('docblockr.spacer_between_sections', False) + settings.set('docblockr.function_description', True) if int(sublime.version()) < 3000: self.edit = self.view.begin_edit() @@ -114,7 +114,7 @@ def test_parameters_are_added_to_function_templates(self): def test_parameters_are_added_to_function_template_with_description_disabled(self): self.set_view_content('/**|\nfunction foo (bar, baz) {') - self.view.settings().set('jsdocs_function_description', False) + self.view.settings().set('docblockr.function_description', False) self.run_doc_blockr() self.assertDocBlockrResult([ '/**', @@ -127,8 +127,8 @@ def test_parameters_are_added_to_function_template_with_description_disabled(sel def test_parameters_are_added_to_function_template_with_description_disabled_and_spacers_between_sections(self): self.set_view_content('/**|\nfunction foo (bar, baz) {') - self.view.settings().set('jsdocs_function_description', False) - self.view.settings().set('jsdocs_spacer_between_sections', True) + self.view.settings().set('docblockr.function_description', False) + self.view.settings().set('docblockr.spacer_between_sections', True) self.run_doc_blockr() self.assertDocBlockrResult([ '/**', @@ -142,8 +142,8 @@ def test_parameters_are_added_to_function_template_with_description_disabled_and def test_parameters_are_added_to_function_template_with_description_disabled_and_spacer_after_description_isset(self): self.set_view_content('/**|\nfunction foo (bar, baz) {') - self.view.settings().set('jsdocs_function_description', False) - self.view.settings().set('jsdocs_spacer_between_sections', 'after_description') + self.view.settings().set('docblockr.function_description', False) + self.view.settings().set('docblockr.spacer_between_sections', 'after_description') self.run_doc_blockr() self.assertDocBlockrResult([ '/**', @@ -237,7 +237,7 @@ class TestPHP(ViewTestCase): def get_syntax_file(self): # Allows overriding with custom syntax - php_syntax_file = self.view.settings().get('doc_blockr_tests_php_syntax_file') + php_syntax_file = self.view.settings().get('docblockr.tests_php_syntax_file') if not php_syntax_file: return 'Packages/PHP/PHP.tmLanguage' else: @@ -374,7 +374,7 @@ def test_issue_372_property_with_short_array_syntax(self): def test_optional_function_description(self): self.set_view_content(" Date: Thu, 15 Jun 2017 20:33:13 +0100 Subject: [PATCH 2/2] Fix Menu settings file paths --- Main.sublime-menu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Main.sublime-menu b/Main.sublime-menu index 71627a6..9acd678 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -25,14 +25,14 @@ "caption": "Settings – Default", "command": "open_file", "args": { - "file": "${packages}/DocBlockr/Base File.sublime-settings" + "file": "${packages}/DocBlockr/Preferences.sublime-settings" } }, { "caption": "Settings – User", "command": "open_file", "args": { - "file": "${packages}/User/Base File.sublime-settings" + "file": "${packages}/User/Preferences.sublime-settings" } }, {