Skip to content

Commit

Permalink
Verify server version match
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoah1 committed Dec 26, 2024
1 parent 0c2fd00 commit 426950c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
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

0 comments on commit 426950c

Please sign in to comment.