javascriptnode.jstypescriptautocompleteproto

Is there a way to get autocomplete for .proto JavaScript generated code?


I've written a simple .proto file

syntax = "proto3";

message Event {
  optional string name = 1;
}

I've downloaded the protoc linux compiler (protoc-3.19.3-linux-x86_64.zip) and installed it in my local machine outside of the project's folder.

Then I installed the core runtime dependency with

$ npm i google-protobuf

My package.json shows:

"google-protobuf": "^3.19.3",

I then ran this line to generate the JS code from the .proto file

$ protoc --js_out=import_style=commonjs,binary:. protos/event.proto

It outputs some generated code that I can import with

const Schema = require("./protos/event_pb");

by inspecting Schema.Event I can see that my prop .name is in there, but I can't get any autocomplete going. Is there a way to achieve this?


Solution

  • Turns out there are some well-maintained npm packages that handle these things.

    https://www.npmjs.com/package/protobufjs or https://www.npmjs.com/package/ts-proto