Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang/Gopls Support #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 39 additions & 2 deletions package-lock.json

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

31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,29 @@
},
"default": []
},
"bsv.golang.enabled": {
"type": "boolean",
"description": "If false, disable the golang component",
"default": true
},
"bsv.golang.gopackagesdriver.goSdkWorkspaceName": {
"type": "string",
"default": "go_sdk",
"description": "Name of the bazel external workspace for the go_sdk. This is used to calculate the GOROOT dir"
},
"bsv.golang.gopackagesdriver.release": {
"type": "string",
"default": "v1.4.3",
"description": "The release tag of the gopackagesdriver client executable"
},
"bsv.golang.gopackagesdriver.flags": {
"type": "array",
"description": "optional flags for the gopackagesdriver client executable",
"items": {
"type": "string"
},
"default": []
},
"bsv.bzldoc.base-url": {
"type": "string",
"default": "https://docs.bazel.build/versions/master",
Expand Down Expand Up @@ -494,6 +517,12 @@
"title": "Buildozer: Run Command Wizard",
"icon": "$(zap)"
},
{
"category": "Bzl",
"command": "bsv.golang.gopls.wizard",
"title": "Golang: Configure gopls",
"icon": "$(zap)"
},
{
"category": "Bzl",
"command": "bsv.bzl.redo",
Expand Down Expand Up @@ -772,6 +801,7 @@
"bazel-stack-vscode-api": "^1.2.2",
"find-up": "^5.0.0",
"fs-extra": "9.0.1",
"get-port": "^5.1.1",
"graceful-fs": "4.2.4",
"luxon": "1.24.1",
"mv": "^2.1.1",
Expand All @@ -796,6 +826,7 @@
"@types/chai-string": "1.4.2",
"@types/find-up": "^4.0.0",
"@types/fs-extra": "9.0.1",
"@types/get-port": "^4.2.0",
"@types/glob": "^7.1.1",
"@types/graceful-fs": "4.1.2",
"@types/luxon": "1.24.3",
Expand Down
4 changes: 3 additions & 1 deletion src/bezel/bes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export class BuildEventService extends RunnableComponent<BuildEventServiceConfig
// Intentionally write an empty / invalid request and expect
// server responds with InvalidArgument.
stream.write({}, (args: any) => {
console.log('bes write args', args);
if (args) {
console.log('bes write args', args);
}
});
});
}
Expand Down
41 changes: 37 additions & 4 deletions src/bezel/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ProtoGrpcType as BzlProtoType } from '../proto/bzl';
import { ProtoGrpcType as CodesearchProtoType } from '../proto/codesearch';
import { getGRPCCredentials, loadBzlProtos, loadCodesearchProtos } from './proto';
import { ConfigurationContext } from '../common';
import getPort = require('get-port');
import { Container } from '../container';

/**
* Configuration for a generic component.
Expand Down Expand Up @@ -131,8 +133,20 @@ export interface LanguageServerConfiguration extends ComponentConfiguration {
enableCodelensTest: boolean;
// enable run codelens
enableCodelensRun: boolean;
// address for gopackagesdriver server
gopackagesdriver: GopackagesdriverServerConfiguration,
}

export interface GopackagesdriverServerConfiguration {
// bind host for the gopackagesdriver server
host: string;
// bind port for the gopackagesdriver server
port: number;
// directory where server assets are located
workspaceDir: string;
}


export interface StarlarkDebuggerConfiguration extends ComponentConfiguration {
autoLaunch: boolean;
debugAdapterExecutable: string,
Expand Down Expand Up @@ -249,6 +263,7 @@ export class BzlSettings extends Settings<BzlConfiguration> {
protected async configure(config: vscode.WorkspaceConfiguration): Promise<BzlConfiguration> {
const bazel = await this.bazel.get();
const address = vscode.Uri.parse(config.get<string>('address', 'grpc://localhost:8085'));

const cfg: BzlConfiguration = {
enabled: config.get<boolean>('enabled', true),
autoLaunch: config.get<boolean>('autoLaunch', true),
Expand Down Expand Up @@ -362,10 +377,20 @@ export class LanguageServerSettings extends Settings<LanguageServerConfiguration
): Promise<LanguageServerConfiguration> {
const bzl = await this.bzl.get();

const gopackagesdriver: GopackagesdriverServerConfiguration = {
host: 'localhost',
port: await getPort({ port: 10022 }),
workspaceDir: Container.file('src', 'golang', 'gopackagesdriver').fsPath,
};

const cfg: LanguageServerConfiguration = {
enabled: config.get<boolean>('enabled', true),
executable: bzl.executable,
command: config.get<string[]>('command', ['lsp', 'serve', '--log_level=info']),
command: config.get<string[]>('command', [
'lsp',
'serve',
'--log_level=info',
]),
enableCodelenses: config.get<boolean>('enableCodelenses', true),
enableCodelensCopyLabel: config.get<boolean>('enableCodelensCopyLabel', true),
enableCodelensCodesearch: config.get<boolean>('enableCodelensCodesearch', true),
Expand All @@ -374,9 +399,13 @@ export class LanguageServerSettings extends Settings<LanguageServerConfiguration
enableCodelensBuild: config.get<boolean>('enableCodelensBuild', true),
enableCodelensTest: config.get<boolean>('enableCodelensTest', true),
enableCodelensRun: config.get<boolean>('enableCodelensRun', true),
gopackagesdriver: gopackagesdriver,
};

cfg.command.push(`--address=${bzl.address}`);
cfg.command.push(`--gopackagesdriver_address=${gopackagesdriver.host}:${gopackagesdriver.port}`);
cfg.command.push(`--gopackagesdriver_aspect_label=@gopackagesdriver//:aspect.bzl`);
cfg.command.push(`--gopackagesdriver_build_flags=--override_repository=gopackagesdriver=${gopackagesdriver.workspaceDir}`);

const subscription = await this.subscription.get();
if (!subscription.token) {
Expand Down Expand Up @@ -434,8 +463,8 @@ export async function setServerExecutable(
}

/**
* Installs bzl. If the expected file already exists the
* download operation is skipped.
* Installs bzl. If the expected file already exists the download operation is
* skipped.
*
* @param cfg The configuration
* @param storagePath The directory where the binary should be installed
Expand All @@ -446,7 +475,11 @@ export async function maybeInstallExecutable(
): Promise<vscode.Uri> {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;
const downloader = await BzlAssetDownloader.fromConfiguration(cfg);
const downloader = await BzlAssetDownloader.fromConfiguration({
basename: 'bzl',
downloadBaseURL: cfg.downloadBaseURL,
release: cfg.release,
});
const mode = 0o755;
return downloader.getOrDownloadFile(ctx, mode, cancellationToken);
}
1 change: 1 addition & 0 deletions src/bezel/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export enum CommandName {
DebugBuild = 'bsv.bzl.debugBuild',
AskForDebugTargetLabel = 'bsv.bzl.askForDebugTargetLabel',
BuildozerWizard = 'bsv.buildozer.wizard',
GoplsWizard = 'bsv.golang.gopls.wizard',
LaunchDebugAdapter = 'bsv.bzl.starlarkDebugger.launch',
LaunchRemoteCache = 'bsv.bzl.remoteCache.launch',
LaunchBzlServer = 'bsv.bzl.server.launch',
Expand Down
9 changes: 7 additions & 2 deletions src/bezel/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { getApi, FileDownloader } from '@microsoft/vscode-file-downloader-api';
* Configuration type that describes a desired asset from bzl.io.
*/
export interface BzlAssetConfiguration {
/**
* The basename of the binary, like 'bzl'.
*/
basename: string;

/**
* The base URL (e.g "https://bzl.io").
*/
Expand All @@ -20,10 +25,10 @@ export interface BzlAssetConfiguration {
}

export class BzlAssetDownloader {
private constructor(private downloaderApi: FileDownloader, private cfg: BzlAssetConfiguration) {}
private constructor(private downloaderApi: FileDownloader, private cfg: BzlAssetConfiguration) { }

getBasename(): string {
let basename = 'bzl';
let basename = this.cfg.basename;
if (process.platform === 'win32') {
basename += '.exe';
}
Expand Down
14 changes: 12 additions & 2 deletions src/bezel/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { ConfigurationContext } from '../common';
import findUp = require('find-up');
import path = require('path');
import { Buildozer } from '../buildozer/buildozer';
import { GolangSettings } from '../golang/settings';
import { Golang } from '../golang/golang';

export const BzlFeatureName = 'bsv.bzl';

Expand Down Expand Up @@ -67,8 +69,10 @@ export class BzlFeature implements vscode.Disposable {

constructor(private api: API, ctx: vscode.ExtensionContext, private configCtx: ConfigurationContext) {
let cwd = "."
let workspace: vscode.WorkspaceFolder | undefined;
if (vscode.workspace.workspaceFolders?.length) {
cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
workspace = vscode.workspace.workspaceFolders[0];
cwd = workspace.uri.fsPath;
}
const workspaceFolder = findWorkspaceFolder(cwd);

Expand Down Expand Up @@ -119,6 +123,10 @@ export class BzlFeature implements vscode.Disposable {
new LanguageServerSettings(configCtx, 'bsv.bzl.lsp', bzlSettings, subscriptionSettings)
);

const golangSettings = this.addDisposable(
new GolangSettings(configCtx, 'bsv.golang', ctx, bzlSettings, languageServerSettings)
);

// ======= Components =========

const subscription = this.addComponent(new Subscription(subscriptionSettings, bzlSettings));
Expand Down Expand Up @@ -150,6 +158,7 @@ export class BzlFeature implements vscode.Disposable {
new StarlarkDebugger(debugSettings, bazelSettings, bzlSettings, workspaceFolder)
));
const codeSearch = this.addComponent(new CodeSearch(codeSearchSettings, bzl));
const golang = this.addComponent(new Golang(golangSettings, ctx.storageUri!, workspace, bazelServer));
this.addDisposable(
new BezelWorkspaceView(
lspClient,
Expand All @@ -162,7 +171,8 @@ export class BzlFeature implements vscode.Disposable {
bazelServer,
starlarkDebugger,
codeSearch,
invocations
invocations,
golang,
)
);
}
Expand Down
Loading