Skip to content

Commit

Permalink
初始化 VSCode 插件项目 #658
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Apr 26, 2024
1 parent 5f48e52 commit feedd33
Show file tree
Hide file tree
Showing 13 changed files with 1,148 additions and 8 deletions.
1 change: 1 addition & 0 deletions _vscode_plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**.vsix
**/protected.txt
**/test.dosc
**/SavedFileCompletionItemProvider.json
Binary file added _vscode_plugin/Sillot/media/dep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions _vscode_plugin/Sillot/media/dep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _vscode_plugin/Sillot/media/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 86 additions & 3 deletions _vscode_plugin/Sillot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
"name": "sillot",
"displayName": "汐洛 Sillot",
"description": "汐洛官方插件",
"version": "0.1.1100",
"version": "0.1.1200",
"preview": true,
"repository": "/~https://github.com/Hi-Windom/Sillot",
"publisher": "Hi-Windom",
"icon": "media/icon.png",
"galleryBanner": {
"color": "#C80000",
"theme": "dark"
},
"keywords": [
"ms-ceintl.vscode-language-pack-zh-hans"
],
"extensionDependencies": [],
"markdown": "github",
"engines": {
"vscode": "^1.88.0"
},
Expand All @@ -17,6 +28,7 @@
"onDidChangeActiveTextEditor",
"onLanguage:plaintext",
"onLanguage:json",
"onLanguage:jsonc",
"onLanguage:go",
"onLanguage:javascript",
"onLanguage:typescript",
Expand All @@ -33,16 +45,42 @@
],
"main": "./dist/extension.js",
"contributes": {
"configuration": {
"type": "object",
"title": "汐洛插件配置",
"properties": {
"typescript.useCodeSnippetsOnMethodSuggest": {
"type": "boolean",
"default": false,
"description": "Complete functions with their parameter signature."
},
"sillot.typescript.tsdk": {
"type": [
"string",
"null"
],
"default": null,
"markdownDescription": "Specifies the folder path containing the tsserver and `lib*.d.ts` files to use."
}
}
},
"commands": [
{
"command": "sillot.helloWorld",
"title": "Hello World",
"category": "Sillot"
},{
},
{
"command": "sillot.openPackageOnNpm",
"title": "openPackageOnNpm",
"category": "Sillot"
},
{
"command": "sillot.测试序列化字典",
"title": "测试序列化字典",
"category": "Sillot"
},{
},
{
"command": "sillot.测试反序列化字典",
"title": "测试反序列化字典",
"category": "Sillot"
Expand All @@ -53,6 +91,48 @@
"category": "Sillot"
}
],
"viewsContainers": {
"activitybar": [
{
"id": "package-explorer",
"title": "汐洛插件面板",
"icon": "media/dep.svg"
}
]
},
"views": {
"package-explorer": [
{
"id": "nodeDependencies",
"name": "Node Dependencies",
"icon": "media/dep.svg",
"contextualTitle": "Package Explorer"
}
],
"explorer": [
{
"id": "jsonOutline",
"name": "Json Outline",
"when": "jsonOutlineEnabled"
},
{
"id": "ftpExplorer",
"name": "FTP Explorer"
},
{
"id": "fileExplorer",
"name": "File Explorer"
},
{
"id": "testView",
"name": "Test View"
},
{
"id": "testViewDragAndDrop",
"name": "Test View Drag and Drop"
}
]
},
"languages": [
{
"id": "dosc",
Expand Down Expand Up @@ -114,6 +194,9 @@
"@vscode/test-electron": "^2.3.9",
"@vscode/vsce": "^2.26.0",
"eslint": "^8.57.0",
"jsonc-parser": "^3.2.1",
"mkdirp": "^3.0.1",
"rimraf": "^5.0.5",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.91.0",
Expand Down
25 changes: 25 additions & 0 deletions _vscode_plugin/Sillot/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 68 additions & 1 deletion _vscode_plugin/Sillot/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ import { SnippetCompletionItems } from "./provider/db/Snippet";
import { StructCompletionItems } from "./provider/db/Struct";
import { TypeParameterCompletionItems } from "./provider/db/TypeParameter";
import { VariableCompletionItems } from "./provider/db/Variable";
import path from "path";
import { DepNodeProvider } from "./nodeDependencies";
import { FileExplorer } from "./fileExplorer";
import { TestView } from "./testView";
import { TestViewDragAndDrop } from "./testViewDragAndDrop";
import { JsonOutlineProvider } from "./jsonOutline";

let lastChangedDocument: vscode.TextDocument | null = null;
let myWebviewPanel: vscode.WebviewPanel | undefined;

class fileCompletionItemProvider implements vscode.CompletionItemProvider {
private completionItems: vscode.CompletionItem[] = [];
Expand All @@ -43,7 +50,6 @@ class fileCompletionItemProvider implements vscode.CompletionItemProvider {
}
// 序列化并保存到文件
async function saveCompletionItemsToFile(filePath: string, items: Array<vscode.CompletionItem>) {

// 使用 json5.stringify 格式化 JSON,使其更易读
const serializedItems = json5.stringify(items, null, 2);

Expand All @@ -63,7 +69,57 @@ async function loadCompletionItemsFromFile(filePath: string): Promise<Array<vsco
return items;
}

// class MyTreeDataProvider implements vscode.TreeDataProvider<any> {
// onDidChangeTreeData?: vscode.Event<any> | undefined;

// getParent?(element: any) {
// throw new Error("Method not implemented.");
// }
// resolveTreeItem?(item: vscode.TreeItem, element: any, token: vscode.CancellationToken): vscode.ProviderResult<vscode.TreeItem> {
// throw new Error("Method not implemented.");
// }
// getTreeItem(element: any) {
// // 返回树视图中的项
// return {
// label: element,
// collapsibleState: vscode.TreeItemCollapsibleState.None,
// };
// }

// getChildren(element: any) {
// // 返回树视图中的子项
// return Promise.resolve(["项1", "项2", "项3"]);
// }
// }

export function activate(context: vscode.ExtensionContext) {
const rootPath =
vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0
? vscode.workspace.workspaceFolders[0].uri.fsPath
: vscode.extensions.getExtension("Hi-Windom.sillot")?.extensionPath;
vscode.commands.registerCommand("sillot.openPackageOnNpm", moduleName =>
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(`https://www.npmjs.com/package/${moduleName}`))
);
// Samples of `window.registerTreeDataProvider`
const nodeDependenciesProvider = new DepNodeProvider(rootPath);
vscode.window.registerTreeDataProvider("nodeDependencies", nodeDependenciesProvider);
const jsonOutlineProvider = new JsonOutlineProvider(context);
vscode.window.registerTreeDataProvider('jsonOutline', jsonOutlineProvider);
// Samples of `window.createView`
// new FtpExplorer(context);
new FileExplorer(context);

// Test View
new TestView(context);

// new TestViewDragAndDrop(context);

const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBarItem.text = "汐洛插件运行中";
statusBarItem.tooltip = "This is my custom status bar item";
statusBarItem.command = "sillot.helloWorld"; // 可选的命令
statusBarItem.show();

// 监听编辑器切换事件
vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor) {
Expand Down Expand Up @@ -97,6 +153,17 @@ export function activate(context: vscode.ExtensionContext) {
Log.e("汐");
Log.d("洛");
Log.a("汐洛", `${Log.Channel.logLevel}`);

// 获取配置对象
const configuration = vscode.workspace.getConfiguration("Hi-Windom.sillot");

// 获取typescript.useCodeSnippetsOnMethodSuggest的值
const test2 = configuration.get("typescript.useCodeSnippetsOnMethodSuggest") as string;

// 获取sillot.typescript.tsdk的值
const test1 = configuration.get("sillot.typescript.tsdk") as string;
Log.w(test1);
Log.w(test2);
});
const 测试序列化字典 = vscode.commands.registerCommand("sillot.测试序列化字典", async () => {
vscode.window.showInformationMessage("Hello World from Sillot!");
Expand Down
Loading

0 comments on commit feedd33

Please sign in to comment.