Skip to content

Commit

Permalink
Merge pull request #732 from Hi-Windom/v0.34
Browse files Browse the repository at this point in the history
V0.34
  • Loading branch information
Soltus authored May 16, 2024
2 parents 5184f7d + 40c524a commit f66bcd3
Show file tree
Hide file tree
Showing 50 changed files with 1,329 additions and 947 deletions.
2 changes: 0 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* `git clone --depth=1 git@github.com:siyuan-note/siyuan.git`
* switch to dev branch `git checkout dev`

Note: `app/stage/protyle/**` is managed by git lfs, and you don't need to pay attention to it under normal circumstances, related to [#9253](https://github.com/siyuan-note/siyuan/issues/9253).

## User Interface

Install pnpm: `npm install -g pnpm`
Expand Down
2 changes: 0 additions & 2 deletions .github/CONTRIBUTING_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* `git clone --depth=1 git@github.com:siyuan-note/siyuan.git`
* 切换到 dev 分支 `git checkout dev`

备注:`app/stage/protyle/**` 使用 git lfs 管理,正常情况下无需关注,关联 [#9253](https://github.com/siyuan-note/siyuan/issues/9253)。

## NPM 依赖

安装 pnpm:`npm install -g pnpm`
Expand Down
28 changes: 16 additions & 12 deletions .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.1210",
"version": "0.34.1310",
"preview": true,
"repository": "https://github.com/Hi-Windom/Sillot",
"publisher": "Hi-Windom",
Expand All @@ -17,7 +17,7 @@
"extensionDependencies": [],
"markdown": "github",
"engines": {
"vscode": "^1.88.0"
"vscode": "^1.89.0"
},
"categories": [
"Programming Languages",
Expand All @@ -44,7 +44,7 @@
"onLanguage:scss",
"onLanguage:python",
"onLanguage:xml",
"workspaceContains:**/.editorconfig"
"workspaceContains:**/.sillot.jsonc"
],
"main": "./dist/extension.js",
"contributes": {
Expand Down Expand Up @@ -205,6 +205,10 @@
{
"command": "extension.switching",
"title": "汐洛 🤍 git emoji label switching"
},
{
"command": "sillot.运行工作区脚本文件",
"title": "汐洛 🤍 运行工作区脚本文件"
}
],
"submenus": [
Expand Down Expand Up @@ -425,24 +429,24 @@
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.6",
"@types/node": "18.x",
"@types/vscode": "^1.88.0",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@types/node": "~18.19.33",
"@types/vscode": "^1.89.0",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"@vscode/test-cli": "^0.0.8",
"@vscode/test-electron": "^2.3.9",
"@vscode/vsce": "^2.26.0",
"@vscode/test-electron": "^2.3.10",
"@vscode/vsce": "^2.26.1",
"eslint": "^8.57.0",
"jsonc-parser": "^3.2.1",
"mkdirp": "^3.0.1",
"rimraf": "^5.0.5",
"rimraf": "^5.0.7",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@octokit/rest": "^20.1.0",
"@octokit/rest": "^20.1.1",
"fs-extra": "^11.2.0",
"json5": "^2.2.3"
},
Expand Down
2 changes: 2 additions & 0 deletions .vscode/extensions/Sillot/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { loadCompletionItemsFromFile, saveCompletionItemsToFile } from "./utils/
import { add_task_同步更新版本 } from "./task/同步更新版本";
import { registerHoverProvider_链式调用国际化 } from "./provider/typescript";
import { add_task_同步更新packageManager } from "./task/同步更新packageManager";
import { add_task_运行工作区脚本文件 } from "./task/运行工作区脚本文件";

let lastChangedDocument: vscode.TextDocument | null = null;
let myWebviewPanel: vscode.WebviewPanel | undefined;
Expand Down Expand Up @@ -80,6 +81,7 @@ export async function activate(context: vscode.ExtensionContext) {
add_module_git_emoji_zh(context);
add_task_同步更新版本(context);
add_task_同步更新packageManager(context);
add_task_运行工作区脚本文件(context);
registerHoverProvider_链式调用国际化(context);

const addMappingDisposable = vscode.commands.registerCommand("汐洛.addPackageJsonMapping", async (uri: vscode.Uri) => {
Expand Down
61 changes: 9 additions & 52 deletions .vscode/extensions/Sillot/src/provider/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import json5 from "json5";
import * as path from "path";
import { Log } from "../utils/log";
import { C } from "../extension.const";
import { flattenJson, readJSONFile } from "../utils/json";

export function registerHoverProvider_链式调用国际化(context: vscode.ExtensionContext) {
const provider = new SiyuanHoverProvider();
Expand Down Expand Up @@ -45,8 +46,7 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
// 读取.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);
const sillotJson = readJSONFile(sillotJsoncPath);
let combinedHover: vscode.Hover | null = null;
// 获取所有targetExpressions
const targetExpressions = Object.keys(sillotJson.i18n.hover.ts);
Expand Down Expand Up @@ -116,7 +116,7 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
private hoverForCode(key: string, filePath: string, lang: string) {
const resources = getResources(filePath);
const KeyValue = resources.find(item => item.key === key)?.value;

// console.log(key, KeyValue, resources)
if (KeyValue) {
const fileUri = vscode.Uri.file(filePath); // 可以进一步调整到 key 所在行,但是没必要
const keyValueText = `[${lang}](${fileUri}) : **${KeyValue}** \n\n`;
Expand Down Expand Up @@ -175,54 +175,6 @@ class SiyuanHoverProvider implements vscode.HoverProvider {
}
}

function readJSONFile(filePath: string): any {
try {
const content = fs.readFileSync(filePath, "utf-8");
return JSON.parse(content);
} catch (e) {
vscode.window.showErrorMessage(String(e));
return null;
}
}

function flattenJson(jsonData: { [x: string]: any } | any[], parentKey = ""): any[] {
let resources: any[] = [];
let newKey: string;

if (Array.isArray(jsonData)) {
jsonData.forEach((item, index) => {
newKey = parentKey ? `${parentKey}[${index}]` : `[${index}]`;
if (typeof item === "object") {
resources = resources.concat(flattenJson(item, newKey));
} else {
resources.push({
key: newKey,
value: item,
});
}
});
} else if (jsonData !== null && typeof jsonData === "object") {
for (const key in jsonData) {
// Check if the key is a numeric string and treat it as an array index
if (/^\d+$/.test(key)) {
newKey = parentKey ? `${parentKey}[${key}]` : `[${key}]`;
} else {
newKey = parentKey ? `${parentKey}.${key}` : key;
}
if (typeof jsonData[key] === "object") {
resources = resources.concat(flattenJson(jsonData[key], newKey));
} else {
resources.push({
key: newKey,
value: jsonData[key],
});
}
}
}

return resources;
}

function getResources(filePath: string) {
const jsonData = readJSONFile(filePath);
const resources = flattenJson(jsonData);
Expand All @@ -242,7 +194,12 @@ function buildExpressionChain(node: ts.Node): string | undefined {
} else if (ts.isElementAccessExpression(current)) {
// 如果当前节点是元素访问表达式,获取索引并添加到链的前面
const argument = current.argumentExpression;
if (ts.isStringLiteral(argument) || ts.isNumericLiteral(argument)) {
if (ts.isStringLiteral(argument)) {
// 将字符串索引转换为属性访问的形式
expressionChain = "." + argument.text + expressionChain;
current = current.expression;
} else if (ts.isNumericLiteral(argument)) {
// 数值索引保持不变
expressionChain = `[${argument.text}]` + expressionChain;
current = current.expression;
} else {
Expand Down
103 changes: 103 additions & 0 deletions .vscode/extensions/Sillot/src/task/运行工作区脚本文件.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as vscode from "vscode";
import * as path from "path";

export function add_task_运行工作区脚本文件(context: vscode.ExtensionContext) {
const disposable = vscode.commands.registerCommand("sillot.运行工作区脚本文件", async () => {
let batFiles: vscode.Uri[] | undefined = undefined;
const limiter1 = 58;
const fileNameStartWith = "workspace-";
// 使用 withProgress 显示进度
vscode.window
.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: `正在搜索工作区脚本文件(文件名必须以 ${fileNameStartWith} 开头)...`,
cancellable: true,
},
async (progress, token) => {
// vscode.GlobPattern 参考 https://github.com/microsoft/vscode-docs/blob/main/docs/editor/glob-patterns.md
const includes = `{**/${fileNameStartWith}*.bat,**/${fileNameStartWith}*.py,**/${fileNameStartWith}*.js}`
batFiles = await vscode.workspace.findFiles(includes, "**​/node_modules/**", limiter1);
}
)
.then(async () => {
if (batFiles) {
const batFileUris = batFiles.map(file => file.fsPath);
const batFileChoices = batFileUris.map(uri => path.basename(uri));

if (batFileChoices.length === 0) {
vscode.window.showInformationMessage(`工作区未发现有效脚本文件(文件名必须以 ${fileNameStartWith} 开头)`);
return;
}

const selectedBatFile = await vscode.window.showQuickPick(batFileChoices, {
placeHolder: `文件名必须以 ${fileNameStartWith} 开头;最多显示 ${limiter1} 项`,
});
if (!selectedBatFile) {
return; // 用户取消了选择
}

const selectedBatFileUri = batFiles[batFileChoices.indexOf(selectedBatFile)].fsPath;

// 使用 withProgress 显示进度
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: `💥 Run ${selectedBatFile} ...`,
cancellable: true,
},
async (progress, token) => {
return new Promise(async (resolve, reject) => {
// 读取 脚本文件的内容
const batFileData = await vscode.workspace.fs.readFile(vscode.Uri.file(selectedBatFileUri));
const batFileContent = batFileData.toString();
let cmd = ""
let comment:RegExpMatchArray | null = null

// 查找第一行 @REM 注释,并提取其值作为工作目录
const commentLine = batFileContent.split("\n")[0];
if (selectedBatFile.endsWith(".bat")) {
cmd = selectedBatFileUri
comment = commentLine.match(/@REM\s+(.+)/);
} else if (selectedBatFile.endsWith(".py")) {
cmd = `python ${selectedBatFileUri}`
comment = commentLine.match(/#\s+(.+)/);
} else if (selectedBatFile.endsWith(".js")) {
cmd = `node ${selectedBatFileUri}`
comment = commentLine.match(/\/\/\s+(.+)/);
} else {
cmd = selectedBatFileUri
}
let workingDirectory = path.resolve(path.dirname(selectedBatFileUri)); // 将 workingDirectory 解析为绝对路径
if (comment) {
workingDirectory = path.resolve(path.join(workingDirectory, comment[1]));
} else {
vscode.window.showWarningMessage("脚本文件第一行没有定义相对工作路径,使用默认值");
}
// console.log(workingDirectory)
// 创建一个新的 VS Code 内部终端,并设置工作目录
const terminal = vscode.window.createTerminal({
name: selectedBatFile,
cwd: workingDirectory, // 使用提取的工作目录
hideFromUser: false,
});

// 如果用户取消,关闭终端
token.onCancellationRequested(() => {
terminal.dispose();
reject(new Error("User cancelled the build process"));
});

// 运行.脚本文件
terminal.sendText(cmd);
terminal.show();
vscode.window.showInformationMessage("terminal process started.");
});
}
);
}
});
});

context.subscriptions.push(disposable);
}
51 changes: 50 additions & 1 deletion .vscode/extensions/Sillot/src/utils/json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as vscode from "vscode";
import * as vscode from "vscode";
import fs from "fs-extra";
import json5 from "json5";
import path, { resolve } from "path";
Expand Down Expand Up @@ -27,3 +27,52 @@ export async function loadCompletionItemsFromFile(filePath: string): Promise<any
// 返回反序列化后的数组
return items;
}


export function readJSONFile(filePath: string): any {
try {
const content = fs.readFileSync(filePath, "utf-8");
return json5.parse(content);
} catch (e) {
vscode.window.showErrorMessage(String(e));
return null;
}
}

export function flattenJson(jsonData: { [x: string]: any } | any[], parentKey = ""): any[] {
let resources: any[] = [];
let newKey: string;

if (Array.isArray(jsonData)) {
jsonData.forEach((item, index) => {
newKey = parentKey ? `${parentKey}[${index}]` : `[${index}]`;
if (typeof item === "object") {
resources = resources.concat(flattenJson(item, newKey));
} else {
resources.push({
key: newKey,
value: item,
});
}
});
} else if (jsonData !== null && typeof jsonData === "object") {
for (const key in jsonData) {
// Check if the key is a numeric string and treat it as an array index
if (/^\d+$/.test(key)) {
newKey = parentKey ? `${parentKey}[${key}]` : `[${key}]`;
} else {
newKey = parentKey ? `${parentKey}.${key}` : key;
}
if (typeof jsonData[key] === "object") {
resources = resources.concat(flattenJson(jsonData[key], newKey));
} else {
resources.push({
key: newKey,
value: jsonData[key],
});
}
}
}

return resources;
}
2 changes: 1 addition & 1 deletion app/.npmrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shell-emulator=true
virtual-store-dir-max-length=80
# registry=http://mirrors.cloud.tencent.com/npm/
# 已使用 nrm 管理 npm 源 `nrm test` && `nrm use taobao` (换源后需要删除 node_modules 和 lockfile 重新安装)
# 在 Github Action 中通过 `pnpm config set registry https://registry.npmjs.org/ --location project` 改写从而避免镜像问题
virtual-store-dir-max-length=80
2 changes: 1 addition & 1 deletion app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
"syncConfGuide4": "Sync now?",
"syncConfGuide5": "If the amount of data is large, the first sync will be slow, please wait patiently<br>Do not switch apps and keep the screen bright while the iOS/iPad is syncing",
"copyPlainText": "Copy plain text",
"findInDoc": "Match ${y} items in ${x} docs",
"findInDoc": "Matches ${y} blocks in ${x} documents",
"jumpToParentNext": "Jump to the next block of the parent block",
"jumpToParentPrev": "Jump to the previous block of the parent block",
"jumpToParent": "Jump to parent block",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
"syncConfGuide4": "¿Sincronizar ahora?",
"syncConfGuide5": "Si la cantidad de datos es grande, la primera sincronización será lenta, espere pacientemente<br>No cambie de aplicación y mantenga la pantalla brillante mientras iOS/iPad se sincroniza",
"copyPlainText": "Copiar texto sin formato",
"findInDoc": "Hacer coincidir ${y} elementos en ${x} documentos",
"findInDoc": "Coincide con bloques ${y} en documentos ${x}",
"jumpToParentNext": "Saltar al siguiente bloque del bloque principal",
"jumpToParentPrev": "Saltar al bloque anterior del bloque principal",
"jumpToParent": "Saltar al bloque principal",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
"syncConfGuide4": "Synchroniser maintenant ?",
"syncConfGuide5": "Si la quantité de données est importante, la première synchronisation sera lente, veuillez patienter<br> Ne changez pas d'application et gardez l'écran lumineux pendant la synchronisation de l'iOS/iPad",
"copyPlainText": "Copier du texte brut",
"findInDoc": "Faire correspondre les éléments ${y} dans les documents ${x}",
"findInDoc": "Correspond à ${y} blocs dans ${x} documents",
"jumpToParentNext": "Sauter au bloc suivant du bloc parent",
"jumpToParentPrev": "Sauter au bloc précédent du bloc parent",
"jumpToParent": "Sauter au bloc parent",
Expand Down
Loading

0 comments on commit f66bcd3

Please sign in to comment.