php类库到sublime完成
https://badge.juejin.im/entry/5a92c45a5188255efc5f75c4/likes.svg?style=flat-square起因
前一篇写了反射类生成php速查表。过年了在家也没事,想完成自己想要实现的sublime自动完成文件生成。就是sublime里输入关键字后按tab自动补全一个全的函数名和参数的,按tab可以切换一致到最后的。也是给别人的承诺,今年肯定会实现sublime的tp5插件的。
http://i2.运维网.com/images/blog/201802/25/9cb8466b30600793a2bf87750f35cd9d.png
地址在 https://github.com/yangweijie/SublimeThinkPHP5.0
思路
搞清sublime 完成的写法
"HTML_FILE_SUFFIX",
"TEMPLATE_NAME",
{ "trigger": "_ad", "contents": "protected function _after_delete(\\$data,\\$options) {\n ${1:}\n}$0" },
{ "trigger": "_af", "contents": "protected function _after_find(&\\$result,\\$options) {\n${1:}\n}$0" },
{ "trigger": "_ai", "contents": "protected function _after_insert(\\$data,\\$options) {\n ${1:}\n}$0" },
{ "trigger": "_as", "contents": "protected function _after_select(&\\$result,\\$options){\n ${1:foreach(\\$result as &\\$record)\\{\n ${2:\\$this->_after_find(\\$record,\\$options);}\n\\}}\n}$0" },
{ "trigger": "_au", "contents": "protected function _after_update(\\$data,\\$options) {\n ${1:}\n}$0" },
{ "trigger": "_bi", "contents": "protected function _before_insert(&\\$data,\\$options) {\n ${1:}\n}$0" },
{ "trigger": "_bu", "contents": "protected function _before_update(&\\$data,\\$options) {\n ${1:}\n}$0" },
{ "trigger": "->_empty", "contents": "\\$this->_empty()$0" },
{ "trigger": "_get", "contents": "_get('${1:\\$name}')$0" },
{ "trigger": "_post", "contents": "_post('${1:\\$name}')$0" },
{ "trigger": "->_sql", "contents": "->_sql('${1:\\$name}')$0" },
{ "trigger": "->addAll", "contents": "->addAll(\\$${1:dataList},\\$${2:options},\\$${3:replace})$0" },
这个是写在Sublime的ThinkPHP 插件里 php.sublime-completions 文件里的。
completion 和snippet的区别在于 snippet只能一个文件一个补全。命令面版里有提示。
字符串
json 里直接字符串
tab占位
$0 完成的最后光标
tab 选中光标 ${1:XX}1自增下标,: 选中的内容
trigger 触发器
表示什么文本末按tab会触发完成。
注意点
$ 换行之类的要转义
php如何获取
先上核心代码:
页:
[1]