Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
.github/**
.vscode/**
.vscode-test/**
out/test/**
src/**
test-workspaces/**
.envrc
.gitignore
.yarnrc
vsc-extension-quickstart.md
.eslintrc.json
.vscode-test.mjs
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/*.md
**/Makefile
126 changes: 123 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-buf",
"displayName": "Buf",
"description": "Visual Studio Code support for Buf",
"version": "0.6.2",
"version": "0.7.0-devel",
"icon": "logo.png",
"publisher": "bufbuild",
"repository": {
Expand Down Expand Up @@ -49,9 +49,19 @@
"contributes": {
"commands": [
{
"category": "Linters",
"command": "vscode-buf.lint",
"title": "Lint protobuf files using Buf"
"category": "Buf",
"command": "buf.restartServer",
"title": "Restart language server"
},
{
"category": "Buf",
"command": "buf.stopServer",
"title": "Stop language server"
},
{
"category": "Buf",
"command": "buf.outputPanel",
"title": "Reveal output panel"
}
],
"configuration": {
Expand Down Expand Up @@ -89,13 +99,22 @@
"Protobuf"
],
"configuration": "./protobuf-language-configuration.json"
},
{
"//": "This is a special language used by the 'declaration' part of hover inlays in Markdown.",
"id": "proto-decl"
}
],
"grammars": [
{
"language": "proto",
"scopeName": "source.proto",
"path": "./syntaxes/proto.tmLanguage.json"
"path": "./syntaxes/proto.json"
},
{
"language": "proto-decl",
"scopeName": "source.proto-decl",
"path": "./syntaxes/proto-decl.json"
}
]
},
Expand All @@ -110,6 +129,9 @@
"test": "vscode-test",
"package": "vsce package"
},
"dependencies": {
"vscode-languageclient": "^9.0.0"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/node": "^20.x",
Expand Down
62 changes: 62 additions & 0 deletions src/binary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";

import { Error, Result } from "./error";

import pkg from "../package.json";

/**
* A located Buf CLI binary.
*/
export class Binary {
cwd: string
path: string

constructor(cwd: string, path: string) {
this.cwd = cwd
this.path = path
}

static find(defaultPath: string = defaultBinaryPath): Result<Binary> {
let workspace = findWorkspacePath()
if (workspace instanceof Error) {
return workspace
}

let config = vscode.workspace.getConfiguration("buf");
let binaryPath = config!.get<string>("binaryPath");
if (binaryPath === undefined) {
return new Error("Buf CLI path was not set");
}

if (!path.isAbsolute(binaryPath) && binaryPath !== defaultPath) {
// Check if file exists.
binaryPath = path.join(workspace, binaryPath);
if (!fs.existsSync(binaryPath)) {
return new Error(`Buf CLI does not exist: file not found: ${binaryPath}`);
}
}

return new Binary(workspace, binaryPath)
}
}

const defaultBinaryPath = pkg.contributes.configuration.properties["buf.binaryPath"].default;

export function findWorkspacePath(): Result<string> {
if (vscode.workspace.workspaceFolders === undefined) {
return new Error("workspace folders was undefined");
}

if (vscode.workspace.workspaceFolders.length === 0) {
return new Error("workspace folders was not set");
}

let uri = vscode.workspace.workspaceFolders[0].uri;
if (uri.scheme !== "file") {
return new Error(`uri was not file: ${uri.scheme}`);
}

return uri.fsPath;
}
Loading