tp.Res preview

This commit is contained in:
zhbaor 2025-02-07 21:44:26 +08:00
commit dc5bedfc94
9 changed files with 3270 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
node_modules
.vscode-test/
*.vsix

8
.vscode/extensions.json vendored Normal file
View file

@ -0,0 +1,8 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
]
}

17
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,17 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
}
]
}

10
.vscodeignore Normal file
View file

@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
test/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/jsconfig.json
**/*.map
**/eslint.config.mjs
**/.vscode-test.*

27
eslint.config.mjs Normal file
View file

@ -0,0 +1,27 @@
import globals from "globals";
export default [
{
files: ["**/*.js"],
languageOptions: {
globals: {
...globals.commonjs,
...globals.node,
...globals.mocha,
},
ecmaVersion: 2022,
sourceType: "module",
},
rules: {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn",
},
},
];

64
extension.js Normal file
View file

@ -0,0 +1,64 @@
const vscode = require("vscode");
const path = require("path");
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const disposable = vscode.languages.registerHoverProvider("python", {
/**
* @param {vscode.TextDocument} document
* @param {vscode.Position} position
* @param {vscode.CancellationToken} token
*/
async provideHover(document, position, token) {
const { activeSignature, signatures } =
await vscode.commands.executeCommand(
"vscode.executeSignatureHelpProvider",
document.uri,
position
);
const { label, parameters, activeParameter } =
signatures[activeSignature];
const type_name = label
.substring(...parameters[activeParameter].label)
.split(":")
.at(-1)
.trim();
const type_list = type_name.split("|").map((x) => x.trim());
if (!type_list.includes("Res")) return;
const code_line = document.lineAt(position).text;
const res_range = document.getWordRangeAtPosition(position, /".*?"/);
// let start, end;
// for (start = position.character; start >= 0; --start)
// if (code_line.charAt(start) == '"') break;
// for (end = position.character; end < code_line.length; ++end)
// if (code_line.charAt(end) == '"') break;
// let res = code_line.substring(start + 1, end);
// console.log(document.getWordRangeAtPosition(position, /".*?"/));
let res = code_line.substring(
res_range.start.character + 1,
res_range.end.character - 1
);
console.log(res);
if (!res.endsWith(".jpg")) res += ".png";
const img_path = path.join(
vscode.workspace.workspaceFolders[0].uri.path,
"mower",
"resources",
res
);
const md = new vscode.MarkdownString(`![](file://${img_path})`);
return new vscode.Hover(md);
},
});
context.subscriptions.push(disposable);
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};

13
jsconfig.json Normal file
View file

@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "Node16",
"target": "ES2022",
"checkJs": false, /* Typecheck .js files. */
"lib": [
"ES2022"
]
},
"exclude": [
"node_modules"
]
}

3098
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

30
package.json Normal file
View file

@ -0,0 +1,30 @@
{
"name": "mower-ng-ext",
"displayName": "mower-ng ext",
"description": "Enhance mower-ng development experience",
"version": "0.0.1",
"engines": {
"vscode": "^1.97.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onLanguage:python"
],
"main": "./extension.js",
"contributes": {},
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "vscode-test"
},
"devDependencies": {
"@types/vscode": "^1.97.0",
"@types/mocha": "^10.0.10",
"@types/node": "20.x",
"eslint": "^9.19.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1"
}
}