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

bazel-bsp server auto-update based on configured version #30

Merged
merged 1 commit into from
Dec 27, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/server/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class BazelBSPInstaller {
.join(' ')

// Full install command including flags.
const installCommand = `"${coursierPath}" launch --jvm 11+ ${MAVEN_PACKAGE}:${config.serverVersion} -M ${INSTALL_METHOD} -- ${flagsString}`
const installCommand = `"${coursierPath}" launch --jvm openjdk:1.17.0 ${MAVEN_PACKAGE}:${config.serverVersion} -M ${INSTALL_METHOD} -- ${flagsString}`

// Report progress in output channel.
const installProcess = cp.spawn(installCommand, {cwd: root, shell: true})
Expand Down
7 changes: 5 additions & 2 deletions src/server/server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {ConnectionDetailsParser} from './connection-details'
import {Utils} from '../utils/utils'
import {INSTALL_BSP_COMMAND} from './install'
import {BspConnectionDetails} from '../bsp/bsp'
import {getExtensionSetting, SettingName} from '../utils/settings'

export const CANCEL_ERROR_CODE = -32603
const SERVER_NAME = 'bazelbsp'
Expand Down Expand Up @@ -96,8 +97,10 @@ export class BuildServerManager implements vscode.Disposable, OnModuleInit {
SERVER_NAME,
rootDir
)

if (connDetails) {
const configuredVersion = getExtensionSetting(
SettingName.BSP_SERVER_VERSION
)
if (connDetails && connDetails?.version === configuredVersion) {
return connDetails
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ suite('BSP Installer', () => {

// Just confirm that coursier path was part of the spawn call, to leave flexibility for other changes to the command.
assert.ok(spawnStub.getCalls()[0].args[0].includes(coursierPath))
assert.ok(spawnStub.getCalls()[0].args[0].includes('--jvm 11+'))
assert.ok(spawnStub.getCalls()[0].args[0].includes('--jvm openjdk:1.17.0'))
assert.ok(installResult)
})

Expand Down
26 changes: 26 additions & 0 deletions src/test/suite/server-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {createSampleMessageConnection} from './test-utils'
import {ConnectionDetailsParser} from '../../server/connection-details'
import {Utils} from '../../utils/utils'
import {BspConnectionDetails} from '../../bsp/bsp'
import * as settings from '../../utils/settings'

suite('Build Server', () => {
let ctx: vscode.ExtensionContext
Expand Down Expand Up @@ -80,6 +81,8 @@ suite('Build Server', () => {
})

test('OnModuleInit', async () => {
sandbox.stub(settings, 'getExtensionSetting').returns('1.0.0')

buildServer.onModuleInit()
assert.equal(ctx.subscriptions.length, 1)
const conn = await buildServer.getConnection()
Expand All @@ -88,19 +91,42 @@ suite('Build Server', () => {
})

test('ServerLaunch', async () => {
sandbox.stub(settings, 'getExtensionSetting').returns('1.0.0')

const listenStub = sinon.stub(sampleConn, 'listen')

buildServer.serverLaunch()
const conn = await buildServer.getConnection()

await appendLinePromise
assert.ok(appendLineStub.calledOnce)
assert.ok(spawnStub.calledOnce)
assert.ok(listenStub.calledOnce)
assert.ok(conn)
})

test('ServerLaunch, version upgrade', async () => {
sandbox.stub(settings, 'getExtensionSetting').returns('1.0.1')
const commandStub = sandbox
.stub(vscode.commands, 'executeCommand')
.resolves(true)

const listenStub = sinon.stub(sampleConn, 'listen')

buildServer.serverLaunch()
const conn = await buildServer.getConnection()

await appendLinePromise
assert.ok(commandStub.calledOnceWith('bazelbsp.install'))
assert.ok(appendLineStub.calledOnce)
assert.ok(spawnStub.calledOnce)
assert.ok(listenStub.calledOnce)
assert.ok(conn)
})

test('Dispose', async () => {
sandbox.stub(settings, 'getExtensionSetting').returns('1.0.0')

buildServer.serverLaunch()
const conn = await buildServer.getConnection()

Expand Down
Loading