Skip to content

个人自用,基于正则表达式来添加头部注释的插件,没有用Ast,因为这是当初还不懂什么叫语法树年轻时期的产物

Notifications You must be signed in to change notification settings

cps-open-source-fork/Comments-Creator

Repository files navigation

简介|Introductions

自用的 jdDoc 格式注释模板注入插件,原理是采用正则匹配,以前不知道有AST模块的时候写的,也没时间重构,就边用边更新了。

注意: 插件市场有专业的功能相似的插件,我只是单纯为了自己用的爽菜写的 😁,才不是因为它配置太复杂才自己造轮子,请有需要的朋友请使用专业插件。

  • 本插件为团队内部打造使用,不对外更新负责,
  • 2023年了,前端建议采用VSCode

功能|Feature

screenshot cps-Comments-Creator

  • 在光标所选的函数上创建jsdoc风格的注释
  • 在新增参数的旧注释上,保留原注释的情况下追加新参数
  • 支持多行写法的函数(参数太多)
  • 支持pyjs系
  • 核心采用了正则匹配,后续可能会更新为AST语法解析的模式(有想法,没时间系列)

使用|Usage

快捷键:Alt + q 在函数行键入即可,暂时 py 使用比较多,js 和 ts 部分语法不能识别,也没空更新

创建注释块

setp1

step1

更新现有注释块

setp2

step2

插件配置|Configure

// Packages/User/cps.sublime-settings
{
  "name": "tett 插件",
  "author": "CPS",
  "mail": "373704015@qq.com", //本插件任何问题请联系qq

  // prettier-ignore
  "cps_comments_creator": {
    // 全局默认配置
    "max_search_count":80,       // 搜索行数(正数从上向下查找, 负数反之)
    "params_alignment":"  ",     // [indent<string>] 是否对齐参数
    "comments_direction":"up",   // "down"|"up" 函数名字上一行,函数名字下一行
    "default_tmpl":{
      "comments_contexts":{
        "Description":true,
        "param":":param {type} {name} {description}",
        "returns":":returns {type} {description}",
      }
    },

    /* 根据后缀名设置 */
    "py": {
      "comments_direction": "down",
      "comments_contexts":{
        "Description":"@Description {description}\n",
        "param":"- param {name} :{type} {description}",
        "returns":"\n@returns `{type}` {description}"
      },
      "comments_header": [
        "    \"\"\"",      // 注释区的开始标识
        "    ",            // 内容位置的前缀
        "    \"\"\"",      // 注释区的结束
      ]
    },

    "js":{
      "comments_contexts":{
        "Description":"@Description - {description}\n",
        "param":"@param {type} {name}  - {description}",
        "returns":"\n@returns {type} - {description}"
      },
      "comments_header": [
        "/**",        //    /**
        " * ",        //     * 内容位置的前缀
        " */"         //     */
      ]
    },

    "mjs":{
      "comments_contexts":{
        "Description":"@Description - {description}\n",
        "param":"@param {type} {name}  - {description}",
        "returns":"\n@returns {type} - {description}"
      },
      "comments_header": [
        "/**",        //    /**
        " * ",        //     * 内容位置的前缀
        " */"         //     */
      ]
    },

    "ts":{
      "comments_contexts":{
        "Description":"@Description - {description}\n",
        "param":"@param {type} {name}  - {description}",
        "returns":"\n@returns {type} - {description}"
      },
      "comments_header": [
        "/**",        // /**
        " * ",        //  * 内容位置的前缀
        " */"         //  */
      ]
    },

    "vue":{
      "comments_contexts":{
        "Description":" @Description {description}\n",
        "param":" @param {type} {name}  {description}",
        "returns":"\n @returns {type} {description}"
      },
      "comments_header": [
        "/**",      // /**
        " * ",      //  * @Description:
        " */"       //  */
      ]
    }
  }
  // prettier-ignore
}

联系方式|Contact

  • 373704015 (qq、wechat、email)

About

个人自用,基于正则表达式来添加头部注释的插件,没有用Ast,因为这是当初还不懂什么叫语法树年轻时期的产物

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages