Skip to content

Commit

Permalink
Merge pull request #731 from Hi-Windom/v0.34
Browse files Browse the repository at this point in the history
V0.34
  • Loading branch information
Soltus authored May 15, 2024
2 parents 6cf7443 + 949aef3 commit 5184f7d
Show file tree
Hide file tree
Showing 34 changed files with 286 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
strategy:
matrix:
config:
- os: ubuntu-22.04
- os: ubuntu-20.04
name: ubuntu build linux.AppImage
kernel_path: "../app/kernel-linux/SiYuan-Sillot-Kernel"
build_args_prefix: "-s -w -X"
Expand All @@ -143,7 +143,7 @@ jobs:
goos: "linux"
goarch: "amd64"
suffix: "linux.AppImage"
- os: ubuntu-22.04
- os: ubuntu-20.04
name: ubuntu build linux.tar.gz
kernel_path: "../app/kernel-linux/SiYuan-Sillot-Kernel"
build_args_prefix: "-s -w -X"
Expand Down
16 changes: 13 additions & 3 deletions .vscode/.sillot.jsonc
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"i18n": {
"siyuan": {
"hover": {
"ts": {
"window_siyuan_languages": {
"zh_CN": ["$vscode.workspace.workspaceFile", "../app/appearance/langs/zh_CN.json"]
"window.siyuan.languages.": {
"zh_CN": ["$workspaceFileDir", "../app/appearance/langs/zh_CN.json"],
"en_US": ["$workspaceFileDir", "../app/appearance/langs/en_US.json"],
"zh_CHT": ["$workspaceFileDir", "../app/appearance/langs/zh_CHT.json"],
"ja_JP": ["$workspaceFileDir", "../app/appearance/langs/ja_JP.json"],
"es_ES": ["$workspaceFileDir", "../app/appearance/langs/es_ES.json"],
"fr_FR": ["$workspaceFileDir", "../app/appearance/langs/fr_FR.json"]
},
"window.sillot.languages.": {
"zh_CN": ["$workspaceFileDir", "../app/appearance/langs/zh_CN.json"],
"en_US": ["$workspaceFileDir", "../app/appearance/langs/en_US.json"],
"ja_JP": ["$workspaceFileDir", "../app/appearance/langs/ja_JP.json"]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions/Sillot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sillot",
"displayName": "汐洛 Sillot",
"description": "汐洛彖夲肜矩阵(Sillot T☳Converbenk Matrix)为智慧新彖务服务。此插件为汐洛官方插件,提供多功能一体化集成。",
"version": "0.34.1100",
"version": "0.34.1210",
"preview": true,
"repository": "https://github.com/Hi-Windom/Sillot",
"publisher": "Hi-Windom",
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions/Sillot/src/extension.const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const C = {
extensionId: "Hi-Windom.sillot",
extensionName: "sillot",
extension_configFileName_workspace: ".sillot.jsonc",
npmjs: "https://www.npmjs.com",
PackageJsonMapping: "PackageJsonMapping.sillot.jsonc",
}
Expand Down
4 changes: 2 additions & 2 deletions .vscode/extensions/Sillot/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { add_module_git_emoji_zh } from "./modules/git_emoji_zh";
import { add_task_unwantedRecommendations_check_by_id } from "./task/unwantedRecommendations";
import { loadCompletionItemsFromFile, saveCompletionItemsToFile } from "./utils/json";
import { add_task_同步更新版本 } from "./task/同步更新版本";
import { registerHoverProvider_window_siyuan_languages } from "./provider/typescript";
import { registerHoverProvider_链式调用国际化 } from "./provider/typescript";
import { add_task_同步更新packageManager } from "./task/同步更新packageManager";

let lastChangedDocument: vscode.TextDocument | null = null;
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext) {
add_module_git_emoji_zh(context);
add_task_同步更新版本(context);
add_task_同步更新packageManager(context);
registerHoverProvider_window_siyuan_languages(context);
registerHoverProvider_链式调用国际化(context);

const addMappingDisposable = vscode.commands.registerCommand("汐洛.addPackageJsonMapping", async (uri: vscode.Uri) => {
if (uri?.fsPath.endsWith("package.json")) {
Expand Down
144 changes: 84 additions & 60 deletions .vscode/extensions/Sillot/src/provider/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import fs from "fs-extra";
import json5 from "json5";
import * as path from "path";
import { Log } from "../utils/log";
import { C } from "../extension.const";

export function registerHoverProvider_window_siyuan_languages(context: vscode.ExtensionContext) {
export function registerHoverProvider_链式调用国际化(context: vscode.ExtensionContext) {
const provider = new SiyuanHoverProvider();
const registration = vscode.languages.registerHoverProvider("typescript", provider);
context.subscriptions.push(registration);
Log.i("registerHoverProvider_window_siyuan_languages 成功");
Log.i("registerHoverProvider_链式调用国际化 成功");
}

class SiyuanHoverProvider implements vscode.HoverProvider {
private expressionChain: string | undefined = undefined;
private 源文件!: ts.SourceFile;
private createSourceFileFromDocument = (文档: vscode.TextDocument): ts.SourceFile => {
const 文件名 = 文档.uri.toString();
const 文本 = 文档.getText();
return ts.createSourceFile(文件名, 文本, ts.ScriptTarget.ESNext, true);
};

provideHover(
document: vscode.TextDocument,
position: vscode.Position,
Expand All @@ -22,6 +30,7 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
const range = document.getWordRangeAtPosition(position);
const word = document.getText(range);
const filePath = document.uri.fsPath;
this.源文件 = this.createSourceFileFromDocument(document);

// 使用TypeScript Compiler API解析文件
const sourceFile = this.getSourceFile(filePath);
Expand All @@ -31,87 +40,102 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
Log.i(`使用TypeScript Compiler API解析 ${filePath} 成功`);

// 查找包含当前位置的表达式
const targetExpression = "window.siyuan.languages.";

const node = this.给我搜(document, position, targetExpression, "startWith");
Log.i("查找包含当前位置的表达式 成功", String(node?.kind));

if (vscode.workspace.workspaceFile && this.expressionChain) {
Log.i(`解析属性访问表达式${this.expressionChain} 成功`);
if (vscode.workspace.workspaceFile) {
const _hasOwnProperty = Object.prototype.hasOwnProperty;
// 读取.sillot.jsonc文件
const workspaceFileDir = path.dirname(vscode.workspace.workspaceFile.fsPath);
const sillotJsoncPath = path.join(workspaceFileDir, ".sillot.jsonc");
const sillotJsoncContent = fs.readFileSync(sillotJsoncPath, "utf-8");
const sillotJson = json5.parse(sillotJsoncContent);
let combinedHover: vscode.Hover | null = null;
// 获取所有targetExpressions
const targetExpressions = Object.keys(sillotJson.i18n.hover.ts);
console.log("targetExpressions", targetExpressions);
for (const t of targetExpressions) {
console.log("t", t);
const node = this.给我搜(position, t, "startWith"); // 主要是给 this.expressionChain 赋值
Log.i("查找包含当前位置的表达式 成功", String(node?.kind));
// 检查当前节点是否属于某个targetExpression
if (this.expressionChain && sillotJson.i18n?.hover?.ts[t]) {
const _key = this.expressionChain.replace(t, "");
const languages = sillotJson.i18n.hover.ts[t];

// 解析zh_CN字段
const zhCNField = sillotJson.i18n.siyuan.ts["window_siyuan_languages"].zh_CN;
if (!zhCNField || zhCNField.length === 0) {
return null;
}
// 解析路径
let zhCNJsonPath: string;
if (zhCNField[0] === "$workspaceFileDir") {
zhCNJsonPath = workspaceFileDir;
} else {
zhCNJsonPath = workspaceFileDir;
}
let combinedHoverText = new vscode.MarkdownString();
let hasMatches = false;

for (const lang in languages) {
if (_hasOwnProperty.call(languages, lang)) {
// 解析每种语言的路径
let langPath: string;
const langField = languages[lang];
if (langField[0] === "$workspaceFileDir") {
langPath = workspaceFileDir;
} else {
langPath = langField[0];
}

// 拼接所有路径片段并处理相对路径
for (let i = 1; i < langField.length; i++) {
langPath = path.resolve(langPath, langField[i]);
}

// 调用hoverForCode为每种语言生成Hover信息
const [keyValueText] = this.hoverForCode(_key, langPath, lang);

if (keyValueText) {
combinedHoverText.appendMarkdown(keyValueText);
hasMatches = true;
}
}
}

// 拼接所有路径片段并处理相对路径
for (let i = 1; i < zhCNField.length; i++) {
zhCNJsonPath = path.resolve(zhCNJsonPath, zhCNField[i]);
if (hasMatches) {
const fileUri = vscode.Uri.file(sillotJsoncPath);
combinedHoverText.appendMarkdown(
`${this.expressionChain} \n\n---\n\nconfig this in **[${C.extension_configFileName_workspace}](${fileUri})**\n\n`
);
// 创建最终的Hover对象
combinedHover = new vscode.Hover(combinedHoverText);
// 找到了直接返回,不需要考虑后面的 targetExpression
return combinedHover;
}
}
this.expressionChain = undefined; // 重置 this.expressionChain
}
const _key = this.expressionChain.replace(targetExpression, "");
Log.i(`hoverForCode ${_key}, ${zhCNJsonPath}`);
return this.hoverForCode(_key, zhCNJsonPath);
}
Log.i("检查是否是`window.siyuan.languages`的属性访问 成功");

return null;
// 返回最终的Hover对象
return null;
}
}

private getSourceFile(filePath: string): ts.SourceFile | undefined {
const program = ts.createProgram([filePath], {});
return program.getSourceFile(filePath);
}

private hoverForCode(key: string, filePath: string) {
private hoverForCode(key: string, filePath: string, lang: string) {
const resources = getResources(filePath);
console.log(key, resources);
let hasMatch = false;
const hoverText: vscode.MarkdownString = new vscode.MarkdownString();
const KeyValue = resources.find(item => item.key === key).value;
const KeyValue = resources.find(item => item.key === key)?.value;

console.log(KeyValue);
if (KeyValue) {
if (!hasMatch) {
hoverText.appendMarkdown(`**filePath**: ${filePath} \n\n\n`);
}
hoverText.appendMarkdown(`- **${key}**: ${KeyValue} \n\n`);
hasMatch = true;
}
if (!hasMatch) {
hoverText.appendMarkdown("**Language definition not found!**");
const fileUri = vscode.Uri.file(filePath); // 可以进一步调整到 key 所在行,但是没必要
const keyValueText = `[${lang}](${fileUri}) : **${KeyValue}** \n\n`;
return [keyValueText];
}
return new vscode.Hover(hoverText);

// 如果没有找到对应的KeyValue,返回空字符串
return [""];
}
private 给我搜(文档: vscode.TextDocument, 位置: vscode.Position, 目标表达式: string, 模式: "equal" | "startWith"): ts.Node | undefined {
const createSourceFileFromDocument = (文档: vscode.TextDocument): ts.SourceFile => {
const 文件名 = 文档.uri.toString();
const 文本 = 文档.getText();
return ts.createSourceFile(文件名, 文本, ts.ScriptTarget.ESNext, true);
};

const 源文件 = createSourceFileFromDocument(文档);
private 给我搜(位置: vscode.Position, 目标表达式: string, 模式: "equal" | "startWith"): ts.Node | undefined {
const isPositionWithinNode = (位置: vscode.Position, 节点: ts.Node): boolean => {
let 开始 = 源文件.getLineAndCharacterOfPosition(节点.getStart());
let 结束 = 源文件.getLineAndCharacterOfPosition(节点.getEnd());
let 开始 = this.源文件.getLineAndCharacterOfPosition(节点.getStart());
let 结束 = this.源文件.getLineAndCharacterOfPosition(节点.getEnd());

// 如果是元素访问表达式,调整结束位置以包含方括号
if (ts.isElementAccessExpression(节点)) {
结束 = 源文件.getLineAndCharacterOfPosition(节点.argumentExpression.getEnd());
结束 = this.源文件.getLineAndCharacterOfPosition(节点.argumentExpression.getEnd());
}

return 开始.line <= 位置.line && 位置.line <= 结束.line && 开始.character <= 位置.character && 位置.character <= 结束.character;
};

Expand All @@ -120,7 +144,7 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
return false;
}
this.expressionChain = buildExpressionChain(节点);
console.log("doesExpressionMatch", this.expressionChain);
console.log("doesExpressionMatch", this.expressionChain, 目标表达式);
if (!this.expressionChain) {
return false;
}
Expand All @@ -147,7 +171,7 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
return undefined;
};

return traverseAndFindNode(源文件);
return traverseAndFindNode(this.源文件);
}
}

Expand Down Expand Up @@ -208,9 +232,9 @@ function getResources(filePath: string) {
function buildExpressionChain(node: ts.Node): string | undefined {
let expressionChain = "";
let current: ts.Node | undefined = node;
console.log("buildExpressionChain", node.getText());
// console.log("buildExpressionChain", node.getText());
while (current) {
console.log("buildExpressionChain current", current.getText());
// console.log("buildExpressionChain current", current.getText());
if (ts.isPropertyAccessExpression(current)) {
// 如果当前节点是属性访问表达式,获取属性名并添加到链的前面
expressionChain = "." + current.name.text + expressionChain;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ Template reference:
```
Web UI: 6806
Container Port: 6806
Container Path: /home/siyuan
Host path: /mnt/user/appdata/siyuan
Container Path: /siyuan/workspace
PUID: 1000
PGID: 1000
Publish parameters: --workspace=/siyuan/workspace/ --accessAuthCode=******(Access authorization code)
Publish parameters: --accessAuthCode=******(Access authorization code)
```

</details>
Expand Down
4 changes: 2 additions & 2 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ services:
```
Web UI: 6806
Container Port: 6806
Container Path: /home/siyuan
Host path: /mnt/user/appdata/siyuan
Container Path: /siyuan/workspace
PUID: 1000
PGID: 1000
Publish parameters: --workspace=/siyuan/workspace/ --accessAuthCode=******(访问授权码)
Publish parameters: --accessAuthCode=******(访问授权码)
```

</details>
Expand Down
9 changes: 9 additions & 0 deletions app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,15 @@
"spellcheckTip": "After enabling, the browser's built-in spell check function will be used. Currently, only English spell check is supported",
"over": "over",
"preview": "Export Preview",
"desktop": "Desktop",
"tablet": "Tablet",
"mobile": "Mobile",
"copyToWechatMP": "Copy to Wechat MP",
"copyToZhihu": "Copy to Zhihu",
"copyToYuque": "Copy to Yuque",
"pasteToWechatMP": "Copied, ready to paste to Wechat MP",
"pasteToZhihu": "Copied, ready to paste to Zhihu",
"pasteToYuque": "Copied, ready to paste to Yuque",
"quote": "Blockquote",
"startRecord": "Start Record",
"endRecord": "End Record",
Expand Down
9 changes: 9 additions & 0 deletions app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@
"spellcheckTip": "Después de habilitar, se utilizará la función de revisión ortográfica integrada del navegador. Actualmente, solo se admite la revisión ortográfica en inglés",
"over": "sobre",
"preview": "Vista previa de la exportación",
"desktop": "Escritorio",
"tablet": "Tablet",
"mobile": "Móvil",
"copyToWechatMP": "Copiar a Wechat MP",
"copyToZhihu": "Copiar a Zhihu",
"copyToYuque": "Copiar a Yuque",
"pasteToWechatMP": "Copiado, listo para pegar en Wechat MP",
"pasteToZhihu": "Copiado, listo para pegar en Zhihu",
"pasteToYuque": "Copiado, listo para pegar en Yuque",
"quote": "Párrafo cita",
"startRecord": "Iniciar grabación",
"endRecord": "Finalizar grabación",
Expand Down
9 changes: 9 additions & 0 deletions app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@
"spellcheckTip": "Après l'activation, la fonction de vérification orthographique intégrée du navigateur sera utilisée. Actuellement, seule la vérification orthographique en anglais est prise en charge",
"over": "over",
"preview": "Aperçu de l'exportation",
"desktop": "bureau",
"tablet": "Tablette",
"mobile": "Mobile",
"copyToWechatMP": "Copier vers Wechat MP",
"copyToZhihu": "Copier vers Zhihu",
"copyToYuque": "Copier vers Yuque",
"pasteToWechatMP": "Copié, prêt à coller sur Wechat MP",
"pasteToZhihu": "Copié, prêt à coller sur Zhihu",
"pasteToYuque": "Copié, prêt à coller sur Yuque",
"quote": "Citation de bloc",
"startRecord": "Début d'enregistrement",
"endRecord": "fin d'enregistrement",
Expand Down
9 changes: 9 additions & 0 deletions app/appearance/langs/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@
"spellcheckTip": "ブラウザの組み込みスペルチェック機能を使用します。現時点では英語のスペルチェックのみがサポートされています",
"over": "以上",
"preview": "プレビュー",
"desktop": "デスクトップ",
"tablet": "タブレット",
"mobile": "携帯端末",
"copyToWechatMP": "Wechat MP にコピーする",
"copyToZhihu": "Zhihu にコピーする",
"copyToYuque": "Yuque にコピーする",
"pasteToWechatMP": "コピー完了、Wechat MP に貼り付け可能",
"pasteToZhihu": "コピー完了、Zhihu に貼り付け可能",
"pasteToYuque": "コピー完了、Yuque に貼り付け可能",
"quote": "引用",
"startRecord": "録音開始",
"endRecord": "録音停止",
Expand Down
Loading

0 comments on commit 5184f7d

Please sign in to comment.