diff --git a/.vscode/launch.json b/.vscode/launch.json index 4055b2fc236e55d34332ea3dd029f2b4b4629810..2bed8921e2803711f9c40a8be24fb242600ae42e 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "runtimeExecutable": "${execPath}", "args": [ "--extensionDevelopmentPath=${workspaceFolder}", - "--disable-extensions" + // "--disable-extensions" ] }, { diff --git a/package-lock.json b/package-lock.json index 00743d1f53e35291d1c13f7d3d53b02fdf193ade..110cb8fdd1907b9fadf2bf97af3931271bf92810 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ChineseInputAssistant", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2055,6 +2055,11 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" }, + "ramda": { + "version": "0.27.1", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.1.tgz", + "integrity": "sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw==" + }, "rc": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", diff --git a/package.json b/package.json index c77828aef585f848a5e6055aac6fa16b46851e91..c72f35db4ee47a0830753cc7739e584f9e77a5a9 100755 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "dependencies": { "pinyin": "^2.9.1", "pinyin-data": "1.0.0", + "ramda": "^0.27.1", "request": "^2.88.2", "wubi-code-data": "1.0.2" }, diff --git "a/\344\276\233\346\265\213\350\257\225/cpp/Circle.cpp" "b/\344\276\233\346\265\213\350\257\225/cpp/Circle.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..911dfa0747ec1f6d6a1c8bfd72ce8f4771439069 --- /dev/null +++ "b/\344\276\233\346\265\213\350\257\225/cpp/Circle.cpp" @@ -0,0 +1,16 @@ +#include "Circle.h" + +Circle::Circle() +{ + this->r = 5.0; +} + +Circle::Circle(double R) +{ + this->r = R; +} + +double Circle::求面积() +{ + return 3.14 * r * r; +} diff --git "a/\344\276\233\346\265\213\350\257\225/cpp/Circle.h" "b/\344\276\233\346\265\213\350\257\225/cpp/Circle.h" new file mode 100644 index 0000000000000000000000000000000000000000..00b7e54d6b8e530f7113622e9fb78e8042d24882 --- /dev/null +++ "b/\344\276\233\346\265\213\350\257\225/cpp/Circle.h" @@ -0,0 +1,15 @@ +#ifndef CIRCLE_H +#define CIRCLE_H + +class Circle +{ +private: + double r; + +public: + Circle(); + Circle(double R); + double 求面积(); +}; + +#endif diff --git "a/\344\276\233\346\265\213\350\257\225/cpp/main.cpp" "b/\344\276\233\346\265\213\350\257\225/cpp/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..64d0c7ad764f78abe0133f0c4eddfd68157be78a --- /dev/null +++ "b/\344\276\233\346\265\213\350\257\225/cpp/main.cpp" @@ -0,0 +1,11 @@ +#include +#include "Circle.h" +using namespace std; + +int main() +{ + Circle 椭圆(3); + // 输入 tuo 补全为 椭圆 再输入 点 + + return 1; +} diff --git "a/\350\241\245\345\205\250\345\256\236\347\216\260.js" "b/\350\241\245\345\205\250\345\256\236\347\216\260.js" index c196dbb692cb3ee9e7a71cc797287f510448c740..fa932438dffba16595c1187a19183242a0744b47 100755 --- "a/\350\241\245\345\205\250\345\256\236\347\216\260.js" +++ "b/\350\241\245\345\205\250\345\256\236\347\216\260.js" @@ -6,10 +6,26 @@ const 百度搜索联想 = require('./lib/百度搜索联想') var pinyin = require("pinyin") var 字符串扩展 = require("./lib/字符串扩展") var { 多重笛卡尔积 } = require("./lib/数组扩展") +var R = require('ramda') function 包含中文(str) { return /.*[\u4e00-\u9fa5]+.*$/.test(str) } +var 数组去重 = 数组 => Array.from(new Set(数组)) +function 查找词组(s) { + var wordPattern = /(-?\d*\.\d\w*)|([^\`\~\!\@\^\&\*\(\)\-\#\?\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s?。,、;:?…—·ˉˇ¨“”~〃|《》〔〕(),]+)/g; + return 数组去重(s.match(wordPattern)) +} +function 获得文档内容(document, position) { + var 总行数 = document.lineCount + var 当前行 = position.line + var 文档内容 = "" + for (var i = 0; i < 总行数; i++) { + if (i != 当前行) + 文档内容 += document.lineAt(i).text + "\n"; + } + return 文档内容 +} function 获得拼音(提示方式, 文本) { var 拼音 = null if (提示方式.indexOf("五笔") != -1) { @@ -45,8 +61,11 @@ function 获得当前输入词() { }) } +var 上次的补全词 = [] var provideCompletionItems_上次调用输入词 = undefined async function provideCompletionItems(document, position, token, context) { + var 当前文件类型 = R.last(document.fileName.split('.')) + var 当前输入词 = await 获得当前输入词() // console.log('当前输入词', 当前输入词) @@ -68,13 +87,30 @@ async function provideCompletionItems(document, position, token, context) { var 系统解析出的关键字 = await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', document.uri, position) 提示文本们 = 提示文本们.concat(系统解析出的关键字.items) + // 对 c/cpp 的特殊处理 + if (当前文件类型 == 'c' || 当前文件类型 == 'cpp') { + // 加入上次的补全词 + 上次的补全词 = 上次的补全词.map(a => a.label).filter(a => a.indexOf('\t') != -1).map(a => a.split('\t')[0]) + 提示文本们 = 提示文本们.concat(上次的补全词.filter(a => !提示文本们.map(b => b.label).includes(a)).map(a => ({ + label: a, + kind: vscode.CompletionItemKind.Text, + }))) + + // 获得当前文档的所有中文 加入候选项 + var 中文词组 = R.compose(R.filter(包含中文), 查找词组)(获得文档内容(document, position)) + 提示文本们 = 提示文本们.concat(中文词组.filter(a => !提示文本们.map(b => b.label).includes(a)).map(a => ({ + label: a, + kind: vscode.CompletionItemKind.Text, + }))) + } + // 获得输入法提供的关键字 if (使用输入法 != 'no') { var func if (使用输入法 == 'Google Pinyin') func = 谷歌输入法 - if (使用输入法 == 'Baidu Sugrec') + else if (使用输入法 == 'Baidu Sugrec') func = 百度搜索联想 var 输入法结果 = await func(当前输入词)(5).catch(e => { @@ -87,8 +123,9 @@ async function provideCompletionItems(document, position, token, context) { }))) } - // 将带中文的标签加入拼音返回 不带中文的不需要包括在返回结果里 - // 经过实验证实 这个函数只需要返回新增的提示 不需要返回原有的提示 + // 将带中文的标签加入拼音返回 + // 不带中文的不需要包括在返回结果里 + // 这个函数只需要返回新增的提示 不需要返回原有的提示 var 返回对象 = 提示文本们.map(补全对象 => { var 文本 = 补全对象.label if (包含中文(文本)) { @@ -100,8 +137,19 @@ async function provideCompletionItems(document, position, token, context) { return r }) } + + // cpp 插件很奇怪 必须要原样返回 + if (当前文件类型 == 'c' || 当前文件类型 == 'cpp') + return [补全对象] + return [] }).flat() + + // 对 c/cpp 的特殊处理 + if (当前文件类型 == 'c' || 当前文件类型 == 'cpp') { + 上次的补全词 = 返回对象 + } + // console.log(返回对象.map(a => a.label).join(',')) return 返回对象 }