Vscode 在扩展中使用导入函数时出错
Vscode gives error when using function from import in extension
对,所以,标题真的不好。但基本上我遇到的问题是,在尝试制作我自己使用的插件版本时,我无法 运行 它。
它停止工作的原因似乎是使用了从另一个本地文件(在打字稿中)导入的函数。我已经尝试了所有我能想到的方法,例如,复制一个工作扩展并仅替换代码,更改编译器设置复制官方扩展示例 github。以及在异步和非异步之间更改函数。
我还尝试 运行从源代码中安装原始插件来测试它是否适合我的环境。但这确实奏效了。 Soooo...我对可能的原因一无所知(导入的函数除外)。
(因为我不知道是什么原因造成的,我真的不知道哪些部分会有帮助,所以下面的一切都不确定必要的水平,我也几乎没有用打字稿或 vscode 之前的扩展)
错误信息
Activating extension 'Kycklingris.vscode-profiles' failed: The "original" argument must be of type function. Received undefined.
我的主要扩展名 .ts 文件,它与注释掉的测试一起工作,但没有注释掉它,并且测试完全是空的。
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { GetProfiles, GetSettings, GetWorkspaceSettings, SetProfiles, SetWorkspaceSettings } from "./settings";
import { CreateProfile, ApplyProfile, EditProfile, DeleteProfile, PickProfile, test } from './utils';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
context.subscriptions.push(
vscode.commands.registerCommand("vscode-profiles.Apply", Apply),
vscode.commands.registerCommand("vscode-profiles.Create", Create),
vscode.commands.registerCommand("vscode-profiles.Edit", Edit),
vscode.commands.registerCommand("vscode-profiles.Delete", Delete),
);
}
export function deactivate() {}
async function Apply() {
test();
//let id = await PickProfile();
//ApplyProfile(id);
}
async function Create() {
//CreateProfile();
}
async function Edit() {
//let id = await PickProfile();
//EditProfile(id);
}
async function Delete() {
//let id = await PickProfile();
//DeleteProfile(id);
}
来自我的 package.json,我已经安装了所有这些,但不是全局的
"devDependencies": {
"@types/node": "^12.20.19",
"@types/vscode": "^1.59.0",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
"eslint": "^7.32.0",
"typescript": "^4.5.0-dev.20210814"
},
"dependencies": {
"sqlite": "^4.0.23",
"sqlite3": "^5.0.2",
"util": "^0.12.4",
"vscode": "^1.1.37"
}
aaaaa 和我的 tsconfig.json
{
"compilerOptions": {
"strict": true, /* enable all strict type-checking options */
"alwaysStrict": false,
"module": "commonjs",
"target": "es2019",
"outDir": "out",
"noImplicitAny": true,
"noImplicitReturns": true,
"lib": [
"es2019"
],
"sourceMap": true,
"strictNullChecks": true,
"rootDir": "src",
"noUnusedLocals": true /* Report errors on unused locals. */
},
"include": [
"./src"
],
"exclude": [
"./test",
"./node_modules",
"./.vscode-test"
]
}
编辑:
utils 文件中可能重要的内容
import * as vscode from "vscode";
import { GetProfiles, GetSettings, SetProfiles, SetWorkspaceSettings, GetProfile, SetProfile } from "./settings";
import { Profile, Extension } from "./types";
import { UpdateExtensions, GetAllExtensions } from "./extensionUtil";
export async function test() {
}
目录结构为:
node_modules/
out/
extension.js
extension.js.map
...
src/
extension.ts
extensionUtil.ts
settings.ts
types.ts
utils.ts
.eslintrc.json
package-lock.json
package.json
tsconfig.json
const fs = require("fs");
const readDir = promisify(fs.readdirectory);
应该是
const fs = require("fs");
const readDir = promisify(fs.readdir);
我不知道为什么会这样,因为这是代码的一部分,我没有写,而是保留了下来。
对,所以,标题真的不好。但基本上我遇到的问题是,在尝试制作我自己使用的插件版本时,我无法 运行 它。
它停止工作的原因似乎是使用了从另一个本地文件(在打字稿中)导入的函数。我已经尝试了所有我能想到的方法,例如,复制一个工作扩展并仅替换代码,更改编译器设置复制官方扩展示例 github。以及在异步和非异步之间更改函数。
我还尝试 运行从源代码中安装原始插件来测试它是否适合我的环境。但这确实奏效了。 Soooo...我对可能的原因一无所知(导入的函数除外)。
(因为我不知道是什么原因造成的,我真的不知道哪些部分会有帮助,所以下面的一切都不确定必要的水平,我也几乎没有用打字稿或 vscode 之前的扩展)
错误信息
Activating extension 'Kycklingris.vscode-profiles' failed: The "original" argument must be of type function. Received undefined.
我的主要扩展名 .ts 文件,它与注释掉的测试一起工作,但没有注释掉它,并且测试完全是空的。
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { GetProfiles, GetSettings, GetWorkspaceSettings, SetProfiles, SetWorkspaceSettings } from "./settings";
import { CreateProfile, ApplyProfile, EditProfile, DeleteProfile, PickProfile, test } from './utils';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
context.subscriptions.push(
vscode.commands.registerCommand("vscode-profiles.Apply", Apply),
vscode.commands.registerCommand("vscode-profiles.Create", Create),
vscode.commands.registerCommand("vscode-profiles.Edit", Edit),
vscode.commands.registerCommand("vscode-profiles.Delete", Delete),
);
}
export function deactivate() {}
async function Apply() {
test();
//let id = await PickProfile();
//ApplyProfile(id);
}
async function Create() {
//CreateProfile();
}
async function Edit() {
//let id = await PickProfile();
//EditProfile(id);
}
async function Delete() {
//let id = await PickProfile();
//DeleteProfile(id);
}
来自我的 package.json,我已经安装了所有这些,但不是全局的
"devDependencies": {
"@types/node": "^12.20.19",
"@types/vscode": "^1.59.0",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
"eslint": "^7.32.0",
"typescript": "^4.5.0-dev.20210814"
},
"dependencies": {
"sqlite": "^4.0.23",
"sqlite3": "^5.0.2",
"util": "^0.12.4",
"vscode": "^1.1.37"
}
aaaaa 和我的 tsconfig.json
{
"compilerOptions": {
"strict": true, /* enable all strict type-checking options */
"alwaysStrict": false,
"module": "commonjs",
"target": "es2019",
"outDir": "out",
"noImplicitAny": true,
"noImplicitReturns": true,
"lib": [
"es2019"
],
"sourceMap": true,
"strictNullChecks": true,
"rootDir": "src",
"noUnusedLocals": true /* Report errors on unused locals. */
},
"include": [
"./src"
],
"exclude": [
"./test",
"./node_modules",
"./.vscode-test"
]
}
编辑: utils 文件中可能重要的内容
import * as vscode from "vscode";
import { GetProfiles, GetSettings, SetProfiles, SetWorkspaceSettings, GetProfile, SetProfile } from "./settings";
import { Profile, Extension } from "./types";
import { UpdateExtensions, GetAllExtensions } from "./extensionUtil";
export async function test() {
}
目录结构为:
node_modules/
out/
extension.js
extension.js.map
...
src/
extension.ts
extensionUtil.ts
settings.ts
types.ts
utils.ts
.eslintrc.json
package-lock.json
package.json
tsconfig.json
const fs = require("fs");
const readDir = promisify(fs.readdirectory);
应该是
const fs = require("fs");
const readDir = promisify(fs.readdir);
我不知道为什么会这样,因为这是代码的一部分,我没有写,而是保留了下来。