admin管理员组

文章数量:1403343

Normally my VSCode installation provides intellisense hints in my Javascript projects. However, I'm having problems getting VSCode to display/register intellisense for message types imported from another JavaScript file which was generated through the protocol buffer piler protoc.

Below is a screenshot of the problem I'm facing. Based on the protobuf file added below, I expect functions of setId(), setName(), setSalary() on the jeff object. However, VSCode does not seem to recognize the Schema.Employee type.

Is there anything I can do to have intellisense work with types which were generated from protocol-buffers?

reprex Tested using VSCode 1.50.1 and protoc version libprotoc 3.13.0:

I piled the following protobuf file using

protoc --js_out=import_style=monjs,binary:. employees.proto

which generates 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 piled 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"
  }
}

Normally my VSCode installation provides intellisense hints in my Javascript projects. However, I'm having problems getting VSCode to display/register intellisense for message types imported from another JavaScript file which was generated through the protocol buffer piler protoc.

Below is a screenshot of the problem I'm facing. Based on the protobuf file added below, I expect functions of setId(), setName(), setSalary() on the jeff object. However, VSCode does not seem to recognize the Schema.Employee type.

Is there anything I can do to have intellisense work with types which were generated from protocol-buffers?

reprex Tested using VSCode 1.50.1 and protoc version libprotoc 3.13.0:

I piled the following protobuf file using

protoc --js_out=import_style=monjs,binary:. employees.proto

which generates 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 piled 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"
  }
}
Share Improve this question asked Oct 28, 2020 at 2:53 HiddenNetworkHiddenNetwork 971 gold badge1 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

In your employees_pb file, you can change the last line to get full intellisense:

module.exports = {...goog, ...proto};
// goog.object.extend(exports, proto);

For some reason the exports extension doesn't work? I opened up this issue on the topic.

本文标签: visual studio codeHow to setup VSCode intellisense for Protobufgenerated JavaScript filesStack Overflow