dufu1991 3 лет назад
Родитель
Сommit
7f44523d1b

+ 6 - 1
packages/vscode-extension/CHANGELOG.md

@@ -1,3 +1,8 @@
+# 0.0.9
+
+- Format source code.
+- Display the current version and the latest version of STDF.
+
 # 0.0.8
 
 - Optimized GitHub Actions configuration.
@@ -13,4 +18,4 @@
 
 # 0.0.1
 
-- Init version.
+- Init version.

+ 7 - 2
packages/vscode-extension/CHANGELOG_CN.md

@@ -1,3 +1,8 @@
+# 0.0.9
+
+- 格式化源码。
+- 显示 STDF 当前版本与最新版本。
+
 # 0.0.8
 
 - 优化 GitHub Actions 配置。
@@ -10,7 +15,7 @@
 # 0.0.6
 
 - 增加 README。(0.0.2 - 0.0.6)
-  
+
 # 0.0.1
 
-- 初始版本。
+- 初始版本。

+ 21 - 0
packages/vscode-extension/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 dufu1991
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 1 - 1
packages/vscode-extension/README.md

@@ -30,4 +30,4 @@ The default API display is in Simplified Chinese. You can enable English API in
 
 # License
 
-This project is licensed under the [MIT License](https://github.com/dufu1991/stdf/blob/main/LICENSE). Feel free to use and contribute to this open-source project.
+This project is licensed under the [MIT License](https://github.com/dufu1991/stdf/blob/main/LICENSE). Feel free to use and contribute to this open-source project.

+ 1 - 2
packages/vscode-extension/README_CN.md

@@ -28,7 +28,6 @@
 
 ![SETTING](https://stdf.design/assets/vscode/setting.png)
 
-
 # 许可证
 
-本项目基于 [MIT 许可证](https://github.com/dufu1991/stdf/blob/main/LICENSE)。请随意享受并贡献给这个开源项目。
+本项目基于 [MIT 许可证](https://github.com/dufu1991/stdf/blob/main/LICENSE)。请随意享受并贡献给这个开源项目。

+ 55 - 55
packages/vscode-extension/package.json

@@ -1,57 +1,57 @@
 {
-    "name": "stdf-vscode-extension",
-    "displayName": "stdf-vscode-extension",
-    "description": "A VS Code extension to facilitate STDF development",
-    "version": "0.0.8",
-    "publisher": "STDF",
-    "icon": "./src/assets/stdf-vscode-extension.png",
-    "main": "./src/extension.js",
-    "engines": {
-        "vscode": "^1.27.0"
-    },
-    "scripts": {
-        "doc": "scripts/doc.sh",
-        "list": "scripts/list.sh",
-        "package": "vsce package",
-        "publish": "vsce publish"
-    },
-    "categories": [
-        "Programming Languages"
-    ],
-    "activationEvents": [
-        "onLanguage:svelte"
-    ],
-    "keywords": [
-        "svelte",
-        "stdf",
-        "component",
-        "api",
-        "javascript"
-    ],
-    "contributes": {
-        "commands": [],
-        "configuration": {
-            "type": "object",
-            "title": "STDF",
-            "properties": {
-                "STDF.English": {
-                    "type": "boolean",
-                    "default": false,
-                    "description": "Whether to enable English or not in stdf-vscode-extension"
-                }
-            }
-        }
-    },
-    "devDependencies": {
-        "vscode": "^1.1.37"
-    },
-    "repository": {
-        "type": "git",
-        "url": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension"
-    },
-    "bugs": {
-        "url": "https://github.com/dufu1991/stdf/issues?q=is:issue+is:open+vscode-extension"
-    },
-    "homepage": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension/README.md",
-    "LICENSE": "https://github.com/dufu1991/stdf/blob/main/LICENSE"
+	"name": "stdf-vscode-extension",
+	"displayName": "stdf-vscode-extension",
+	"description": "A VS Code extension to facilitate STDF development",
+	"version": "0.0.9",
+	"publisher": "STDF",
+	"icon": "./src/assets/stdf-vscode-extension.png",
+	"main": "./src/extension.js",
+	"engines": {
+		"vscode": "^1.27.0"
+	},
+	"scripts": {
+		"doc": "scripts/doc.sh",
+		"list": "scripts/list.sh",
+		"package": "vsce package",
+		"publish": "vsce publish"
+	},
+	"categories": [
+		"Programming Languages"
+	],
+	"activationEvents": [
+		"onLanguage:svelte"
+	],
+	"keywords": [
+		"svelte",
+		"stdf",
+		"component",
+		"api",
+		"javascript"
+	],
+	"contributes": {
+		"commands": [],
+		"configuration": {
+			"type": "object",
+			"title": "STDF",
+			"properties": {
+				"STDF.English": {
+					"type": "boolean",
+					"default": false,
+					"description": "Whether to enable English or not in stdf-vscode-extension"
+				}
+			}
+		}
+	},
+	"devDependencies": {
+		"vscode": "^1.1.37"
+	},
+	"repository": {
+		"type": "git",
+		"url": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension"
+	},
+	"bugs": {
+		"url": "https://github.com/dufu1991/stdf/issues?q=is:issue+is:open+vscode-extension"
+	},
+	"homepage": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension/README.md",
+	"LICENSE": "https://github.com/dufu1991/stdf/blob/main/LICENSE"
 }

+ 91 - 68
packages/vscode-extension/src/extension.js

@@ -6,86 +6,109 @@ const path = require('path');
 const componentListOrgin = require('./menuList');
 const componentList = ArrChildFun(componentListOrgin);
 
-function activate(context) {
-    // 如果没有设置,返回undefined
-    // If not set, return undefined
-    const result = vscode.workspace.getConfiguration().get('STDF');
-    // 获取插件语言
-    // Get plugin language
-    const isZh = result.English ? false : true;
+function activate() {
+	// 如果没有设置,返回undefined
+	// If not set, return undefined
+	const result = vscode.workspace.getConfiguration().get('STDF');
+	// 获取插件语言
+	// Get plugin language
+	const isZh = result.English ? false : true;
 
-    // 读取当前工程的 package.json 文件
-    // Read the package.json file of the current project
-    const packageJson = require(path.join(vscode.workspace.rootPath, 'package.json'));
-    // 判断当前工程是否引入了 stdf 组件库
-    // Determine whether the current project has introduced the stdf component library
-    const isImportStdf = packageJson?.dependencies?.stdf || packageJson?.devDependencies?.stdf ? true : false;
+	// 读取当前工程的 package.json 文件
+	// Read the package.json file of the current project
+	const packageJson = require(path.join(vscode.workspace.rootPath, 'package.json'));
 
-    // 当前文件是 .svelte 文件时且 isImportStdf 为 true 时,才注册悬浮提示
-    // When the current file is a .svelte file and isImportStdf is true, register the hover prompt
-    if (vscode.window.activeTextEditor.document.languageId === 'svelte' && isImportStdf) {
-        vscode.languages.registerHoverProvider('svelte', {
-            provideHover(document, position, token) {
-                // 获取当前悬浮的单词
-                // Get the word currently hovering
-                const word = document.getText(document.getWordRangeAtPosition(position));
-                // 将单词首字母小写
-                // Lowercase the first letter of the word
-                const wordLower = word.charAt(0).toLowerCase() + word.slice(1);
-                // 如果单词为 components 数组中的一项,则显示提示信息,内容为 ../../doc/components/${componentspaths}/api.md 文件的内容
-                // If the word is an item in the components array, the prompt information is displayed, and the content is the content of the ../../doc/components/${componentspaths}/api.md file
-                if (componentList.includes(word)) {
-                    // 获取对应组件的 api.md 文件的路径
-                    // Get the path of the api.md file of the corresponding component
-                    const apiPath = path.join(__dirname, `./doc/components/${wordLower}/api${isZh ? '' : '_en'}.md`);
+	// 判断当前工程是否引入了 stdf 组件库
+	// Determine whether the current project has introduced the stdf component library
+	const isImportStdf = packageJson?.dependencies?.stdf || packageJson?.devDependencies?.stdf ? true : false;
 
-                    // 读取 api.md 文件的内容
-                    // Read the contents of the api.md file
-                    const apiContent = require('fs').readFileSync(apiPath, 'utf-8');
-                    // 在 apiContent 后面添加示例、API、指南、组件源码的链接
-                    // Add links to examples, API, guides, and component source code after apiContent
-                    const baseUrl = 'https://stdf.design/#/components?nav=';
-                    const baseUrlCode = 'https://github.com/dufu1991/stdf/blob/main/packages/stdf/components/';
-                    const baseUrlCodeGitee = 'https://gitee.com/dufu1991/stdf/blob/main/packages/stdf/components/';
-                    const addContent = `**[${isZh ? '示例' : 'Demo'}](${baseUrl}${wordLower}&tab=0&lang=${
-                        isZh ? 'zh_CN' : 'en_US'
-                    })   [API](${baseUrl}${wordLower}&tab=1&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
-                        isZh ? '指南' : 'Guide'
-                    }](${baseUrl}${wordLower}&tab=2&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
-                        isZh ? '源码(GitHub)' : 'Source code(GitHub)'
-                    }](${baseUrlCode}${wordLower}/${word}.svelte)   [${
-                        isZh ? '源码(Gitee)' : 'Source code(Gitee)'
-                    }](${baseUrlCodeGitee}${wordLower}/${word}.svelte)**`;
-                    const allContent = apiContent + '\n\n' + '---' + '\n\n' + addContent;
+	// 如果 isImportStdf 为 true 时,读取 stdf 组件库的版本号做为当前版本号
+	// If isImportStdf is true, read the version number of the stdf component library as the current version number
+	let currentVersion = isImportStdf ? packageJson.dependencies?.stdf || packageJson.devDependencies?.stdf : '';
+	// 如果 currentVersion 开头为 ^,则去掉 ^
+	// If currentVersion starts with ^, remove ^
+	if (currentVersion.startsWith('^')) {
+		currentVersion = currentVersion.slice(1);
+	}
 
-                    // 返回提示信息
-                    // Return prompt information
-                    return new vscode.Hover(allContent);
-                }
-            },
-        });
-    }
+	// 读取 stdf 组件库的最新版本号,文件位置为 ../../stdf/package.json
+	// Read the latest version number of the stdf component library, the file location is ../../stdf/package.json
+	const latestVersion = require('../../stdf/package.json').version;
+
+	// 当前文件是 .svelte 文件时且 isImportStdf 为 true 时,才注册悬浮提示
+	// When the current file is a .svelte file and isImportStdf is true, register the hover prompt
+	if (vscode.window.activeTextEditor.document.languageId === 'svelte' && isImportStdf) {
+		vscode.languages.registerHoverProvider('svelte', {
+			provideHover(document, position) {
+				// 获取当前悬浮的单词
+				// Get the word currently hovering
+				const word = document.getText(document.getWordRangeAtPosition(position));
+				// 将单词首字母小写
+				// Lowercase the first letter of the word
+				const wordLower = word.charAt(0).toLowerCase() + word.slice(1);
+				// 如果单词为 components 数组中的一项,则显示提示信息,内容为 ../../doc/components/${componentspaths}/api.md 文件的内容
+				// If the word is an item in the components array, the prompt information is displayed, and the content is the content of the ../../doc/components/${componentspaths}/api.md file
+				if (componentList.includes(word)) {
+					// 组合当前 STDF 版本和最新版本
+					// Combine the current STDF version and the latest version
+					const versionContent = `${isZh ? '当前版本' : 'Current version'}:${currentVersion}   ${
+						isZh ? '最新版本' : 'Latest version'
+					}:${latestVersion}`;
+
+					// 获取对应组件的 api.md 文件的路径
+					// Get the path of the api.md file of the corresponding component
+					const apiPath = path.join(__dirname, `./doc/components/${wordLower}/api${isZh ? '' : '_en'}.md`);
+
+					// 读取 api.md 文件的内容
+					// Read the contents of the api.md file
+					const apiContent = require('fs').readFileSync(apiPath, 'utf-8');
+					// 在 apiContent 后面添加示例、API、指南、组件源码的链接
+					// Add links to examples, API, guides, and component source code after apiContent
+					const baseUrl = 'https://stdf.design/#/components?nav=';
+					const baseUrlCode = 'https://github.com/dufu1991/stdf/blob/main/packages/stdf/components/';
+					const baseUrlCodeGitee = 'https://gitee.com/dufu1991/stdf/blob/main/packages/stdf/components/';
+					const addContent = `**[${isZh ? '示例' : 'Demo'}](${baseUrl}${wordLower}&tab=0&lang=${
+						isZh ? 'zh_CN' : 'en_US'
+					})   [API](${baseUrl}${wordLower}&tab=1&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
+						isZh ? '指南' : 'Guide'
+					}](${baseUrl}${wordLower}&tab=2&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
+						isZh ? '更新日志' : 'Changelog'
+					}](${baseUrl}${wordLower}&tab=4&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
+						isZh ? '源码(GitHub)' : 'Source code(GitHub)'
+					}](${baseUrlCode}${wordLower}/${word}.svelte)   [${
+						isZh ? '源码(Gitee)' : 'Source code(Gitee)'
+					}](${baseUrlCodeGitee}${wordLower}/${word}.svelte)**`;
+					const allContent =
+						versionContent + '\n\n' + '---' + '\n\n' + apiContent + '\n\n' + '---' + '\n\n' + addContent + '\n\n' + '\n\n' + '---';
+
+					// 返回提示信息
+					// Return prompt information
+					return new vscode.Hover(allContent);
+				}
+			},
+		});
+	}
 }
 
 //数组处理
 //Array processing
 function ArrChildFun(arr) {
-    let newArr = [];
-    for (let e = 0; e < arr.length; e++) {
-        newArr.push(...arr[e].childs);
-    }
-    //再将 newArr 内的 title_en 组成一维数组
-    //Then the title_en in newArr is composed of one-dimensional array
-    let newArr2 = [];
-    for (let e = 0; e < newArr.length; e++) {
-        newArr2.push(newArr[e].title_en);
-    }
-    return newArr2;
+	let newArr = [];
+	for (let e = 0; e < arr.length; e++) {
+		newArr.push(...arr[e].childs);
+	}
+	//再将 newArr 内的 title_en 组成一维数组
+	//Then the title_en in newArr is composed of one-dimensional array
+	let newArr2 = [];
+	for (let e = 0; e < newArr.length; e++) {
+		newArr2.push(newArr[e].title_en);
+	}
+	return newArr2;
 }
 
 function deactivate() {}
 
 module.exports = {
-    activate,
-    deactivate,
+	activate,
+	deactivate,
 };