通常情况下,我的VSCode安装在JavaScript项目中提供智能提示。然而,我遇到了一个问题,无法让VSCode显示/注册从协议缓冲区编译器 protoc
生成的其他JavaScript文件中导入的消息类型的智能提示。
下面是我面临的问题的截图。根据下面添加的protobuf文件,我期望在jeff
对象上有setId()
, setName()
, setSalary()
函数。然而,VSCode似乎无法识别Schema.Employee
类型。
我是否能做些什么使智能提示能够使用从协议缓冲区生成的类型?
reprex 测试使用 VSCode 1.50.1 和 protoc 版本 libprotoc 3.13.0
:
我使用以下命令编译了下面的protobuf文件:
protoc --js_out=import_style=commonjs,binary:. employees.proto
这将生成employees_pb.js
。
employees.proto
syntax = "proto3";
option optimize_for = SPEED;
message Employee {
int32 id = 1;
string name = 2;
float salary = 3;
}
message Employees {
repeated Employee employees = 1;
}
index.js:
// import schema from compiled file
const Schema = require("./employees_pb");
//create a new instance of Employee
const jeff = new Schema.Employee();
jeff.setId(1001); // <-- Intellisense does not work here.
jeff.setName("Jeff");
jeff.setSalary(1001);
package.json:
{
"name": "protobuff",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"google-protobuf": "^3.13.0"
}
}