From d079204a1dc19f800b3d1324ebdbb8a66eb0d298 Mon Sep 17 00:00:00 2001 From: hbybyyang <2451759073@hotmail.com> Date: Mon, 3 Aug 2020 04:02:17 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=AF=B9cpp=E6=8F=92=E4=BB=B6=E5=81=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 如果是c或cpp文件 需要返回解析的所有内容 2 重新加回了 获得当前文档的所有中文 的逻辑 --- package-lock.json | 7 +++- package.json | 1 + .../\346\265\213\350\257\225cpp.cpp" | 10 +++++ ...45\345\205\250\345\256\236\347\216\260.js" | 39 +++++++++++++++++-- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 "\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" diff --git a/package-lock.json b/package-lock.json index 00743d1..110cb8f 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 c77828a..c72f35d 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/\346\265\213\350\257\225cpp.cpp" "b/\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" new file mode 100644 index 0000000..19c6b27 --- /dev/null +++ "b/\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" @@ -0,0 +1,10 @@ +int main() +{ + int aaa = 1; + int 中文变量 = 2; + + // 输入 zw + + + return 0; +} 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 c196dbb..b51fdb0 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) { @@ -47,6 +63,8 @@ function 获得当前输入词() { var provideCompletionItems_上次调用输入词 = undefined async function provideCompletionItems(document, position, token, context) { + var 当前文件类型 = R.last(document.fileName.split('.')) + var 当前输入词 = await 获得当前输入词() // console.log('当前输入词', 当前输入词) @@ -68,13 +86,20 @@ async function provideCompletionItems(document, position, token, context) { var 系统解析出的关键字 = await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', document.uri, position) 提示文本们 = 提示文本们.concat(系统解析出的关键字.items) + // 获得当前文档的所有中文 加入候选项 + var 中文词组 = R.compose(R.filter(包含中文), 查找词组)(获得文档内容(document, position)) + 提示文本们 = 提示文本们.concat(中文词组.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 +112,9 @@ async function provideCompletionItems(document, position, token, context) { }))) } - // 将带中文的标签加入拼音返回 不带中文的不需要包括在返回结果里 - // 经过实验证实 这个函数只需要返回新增的提示 不需要返回原有的提示 + // 将带中文的标签加入拼音返回 + // 不带中文的不需要包括在返回结果里 + // 这个函数只需要返回新增的提示 不需要返回原有的提示 var 返回对象 = 提示文本们.map(补全对象 => { var 文本 = 补全对象.label if (包含中文(文本)) { @@ -100,9 +126,14 @@ async function provideCompletionItems(document, position, token, context) { return r }) } + + // cpp 插件很奇怪 必须要原样返回 + if (当前文件类型 == 'c' || 当前文件类型 == 'cpp') + return [补全对象] + return [] }).flat() - // console.log(返回对象.map(a => a.label).join(',')) + console.log(返回对象.map(a => a.label).join(',')) return 返回对象 } -- Gitee From ff3d8cbb7cc61d8c5d976eaf074ee4cdf70f4c16 Mon Sep 17 00:00:00 2001 From: hbybyyang <2451759073@hotmail.com> Date: Mon, 3 Aug 2020 04:06:49 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=85=B3=E9=97=AD=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\350\241\245\345\205\250\345\256\236\347\216\260.js" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b51fdb0..39e205d 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" @@ -133,7 +133,7 @@ async function provideCompletionItems(document, position, token, context) { return [] }).flat() - console.log(返回对象.map(a => a.label).join(',')) + // console.log(返回对象.map(a => a.label).join(',')) return 返回对象 } -- Gitee From 17bdd5d54b078b45706f8472749cc60f93c84f5f Mon Sep 17 00:00:00 2001 From: hbybyyang <2451759073@hotmail.com> Date: Mon, 3 Aug 2020 04:54:17 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=8E=B7=E5=BE=97=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=9A=84=E6=89=80=E6=9C=89=E4=B8=AD=E6=96=87?= =?UTF-8?q?=20=E5=AF=B9=20c/cpp=20=E7=9A=84=E7=89=B9=E6=AE=8A=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\241\245\345\205\250\345\256\236\347\216\260.js" | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 39e205d..35e579e 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" @@ -87,11 +87,14 @@ async function provideCompletionItems(document, position, token, context) { 提示文本们 = 提示文本们.concat(系统解析出的关键字.items) // 获得当前文档的所有中文 加入候选项 - var 中文词组 = R.compose(R.filter(包含中文), 查找词组)(获得文档内容(document, position)) - 提示文本们 = 提示文本们.concat(中文词组.map(a => ({ - label: a, - kind: vscode.CompletionItemKind.Text, - }))) + // 对 c/cpp 的特殊处理 + if (当前文件类型 == 'c' || 当前文件类型 == 'cpp') { + var 中文词组 = R.compose(R.filter(包含中文), 查找词组)(获得文档内容(document, position)) + 提示文本们 = 提示文本们.concat(中文词组.map(a => ({ + label: a, + kind: vscode.CompletionItemKind.Text, + }))) + } // 获得输入法提供的关键字 if (使用输入法 != 'no') { -- Gitee From 0bdb7d8179444da08e45c9ffd23c8321cd7caea1 Mon Sep 17 00:00:00 2001 From: hbybyyang <2451759073@hotmail.com> Date: Tue, 4 Aug 2020 00:51:21 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B+?= =?UTF-8?q?=E5=8E=BB=E9=87=8D+cpp=E7=BB=93=E6=9E=84=E4=BD=93=E8=A1=A5?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 2 +- .../cpp/Circle.cpp" | 16 ++++++++++++++++ .../cpp/Circle.h" | 15 +++++++++++++++ .../cpp/main.cpp" | 13 +++++++++++++ .../\346\265\213\350\257\225cpp.cpp" | 10 ---------- ...245\345\205\250\345\256\236\347\216\260.js" | 18 ++++++++++++++++-- 6 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 "\344\276\233\346\265\213\350\257\225/cpp/Circle.cpp" create mode 100644 "\344\276\233\346\265\213\350\257\225/cpp/Circle.h" create mode 100644 "\344\276\233\346\265\213\350\257\225/cpp/main.cpp" delete mode 100644 "\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" diff --git a/.vscode/launch.json b/.vscode/launch.json index 4055b2f..2bed892 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/\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 0000000..911dfa0 --- /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 0000000..00b7e54 --- /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 0000000..d6342f1 --- /dev/null +++ "b/\344\276\233\346\265\213\350\257\225/cpp/main.cpp" @@ -0,0 +1,13 @@ +#include +#include "Circle.h" +using namespace std; + +int main() +{ + Circle 椭圆(3); + // 输入 tuo 补全为 椭圆 再输入 点 + + + + return 1; +} diff --git "a/\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" "b/\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" deleted file mode 100644 index 19c6b27..0000000 --- "a/\344\276\233\346\265\213\350\257\225/\346\265\213\350\257\225cpp.cpp" +++ /dev/null @@ -1,10 +0,0 @@ -int main() -{ - int aaa = 1; - int 中文变量 = 2; - - // 输入 zw - - - return 0; -} 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 35e579e..fa93243 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" @@ -61,6 +61,7 @@ function 获得当前输入词() { }) } +var 上次的补全词 = [] var provideCompletionItems_上次调用输入词 = undefined async function provideCompletionItems(document, position, token, context) { var 当前文件类型 = R.last(document.fileName.split('.')) @@ -86,11 +87,18 @@ 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(中文词组.map(a => ({ + 提示文本们 = 提示文本们.concat(中文词组.filter(a => !提示文本们.map(b => b.label).includes(a)).map(a => ({ label: a, kind: vscode.CompletionItemKind.Text, }))) @@ -136,6 +144,12 @@ async function provideCompletionItems(document, position, token, context) { return [] }).flat() + + // 对 c/cpp 的特殊处理 + if (当前文件类型 == 'c' || 当前文件类型 == 'cpp') { + 上次的补全词 = 返回对象 + } + // console.log(返回对象.map(a => a.label).join(',')) return 返回对象 } -- Gitee From 8f1071e53e4e3f677bd232a0a466bab1c7ee0563 Mon Sep 17 00:00:00 2001 From: hbybyyang <2451759073@hotmail.com> Date: Tue, 4 Aug 2020 00:52:35 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\344\276\233\346\265\213\350\257\225/cpp/main.cpp" | 2 -- 1 file changed, 2 deletions(-) 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" index d6342f1..64d0c7a 100644 --- "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" @@ -7,7 +7,5 @@ int main() Circle 椭圆(3); // 输入 tuo 补全为 椭圆 再输入 点 - - return 1; } -- Gitee