Skip to content

Commit 079bb52

Browse files
committed
refactor(amazonq): refactor base lsp config
1 parent 7e65155 commit 079bb52

File tree

7 files changed

+72
-123
lines changed

7 files changed

+72
-123
lines changed

packages/amazonq/src/lsp/config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import * as vscode from 'vscode'
6-
import { DevSettings, getServiceEnvVarConfig } from 'aws-core-vscode/shared'
7-
import { LspConfig } from 'aws-core-vscode/amazonq'
6+
import { DevSettings, getServiceEnvVarConfig, BaseLspInstaller } from 'aws-core-vscode/shared'
87

9-
export interface ExtendedAmazonQLSPConfig extends LspConfig {
8+
export interface ExtendedAmazonQLSPConfig extends BaseLspInstaller.LspConfig {
109
ui?: string
1110
}
1211

packages/amazonq/test/e2e/lsp/amazonqLsp.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import { AmazonQLspInstaller } from '../../../src/lsp/lspInstaller'
77
import { defaultAmazonQLspConfig } from '../../../src/lsp/config'
88
import { createLspInstallerTests } from './lspInstallerUtil'
9-
import { LspConfig } from 'aws-core-vscode/amazonq'
9+
import { BaseLspInstaller } from 'aws-core-vscode/shared'
1010

1111
describe('AmazonQLSP', () => {
1212
createLspInstallerTests({
1313
suiteName: 'AmazonQLSPInstaller',
1414
lspConfig: defaultAmazonQLspConfig,
15-
createInstaller: (lspConfig?: LspConfig) => new AmazonQLspInstaller(lspConfig),
15+
createInstaller: (lspConfig?: BaseLspInstaller.LspConfig) => new AmazonQLspInstaller(lspConfig),
1616
targetContents: [
1717
{
1818
bytes: 0,

packages/amazonq/test/e2e/lsp/lspInstallerUtil.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from 'aws-core-vscode/shared'
1919
import * as semver from 'semver'
2020
import { assertTelemetry } from 'aws-core-vscode/test'
21-
import { LspConfig } from 'aws-core-vscode/amazonq'
2221
import { LanguageServerSetup } from 'aws-core-vscode/telemetry'
2322

2423
function createVersion(version: string, contents: TargetContent[]) {
@@ -44,8 +43,8 @@ export function createLspInstallerTests({
4443
resetEnv,
4544
}: {
4645
suiteName: string
47-
lspConfig: LspConfig
48-
createInstaller: (lspConfig?: LspConfig) => BaseLspInstaller.BaseLspInstaller
46+
lspConfig: BaseLspInstaller.LspConfig
47+
createInstaller: (lspConfig?: BaseLspInstaller.LspConfig) => BaseLspInstaller.BaseLspInstaller
4948
targetContents: TargetContent[]
5049
setEnv: (path: string) => void
5150
resetEnv: () => void

packages/amazonq/test/unit/amazonq/lsp/config.test.ts

Lines changed: 58 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,97 +7,73 @@ import assert from 'assert'
77
import { DevSettings } from 'aws-core-vscode/shared'
88
import sinon from 'sinon'
99
import { defaultAmazonQLspConfig, ExtendedAmazonQLSPConfig, getAmazonQLspConfig } from '../../../../src/lsp/config'
10-
import { defaultAmazonQWorkspaceLspConfig, getAmazonQWorkspaceLspConfig, LspConfig } from 'aws-core-vscode/amazonq'
1110

12-
for (const [name, config, defaultConfig, setEnv, resetEnv] of [
13-
[
14-
'getAmazonQLspConfig',
15-
getAmazonQLspConfig,
16-
defaultAmazonQLspConfig,
17-
(envConfig: ExtendedAmazonQLSPConfig) => {
18-
process.env.__AMAZONQLSP_MANIFEST_URL = envConfig.manifestUrl
19-
process.env.__AMAZONQLSP_SUPPORTED_VERSIONS = envConfig.supportedVersions
20-
process.env.__AMAZONQLSP_ID = envConfig.id
21-
process.env.__AMAZONQLSP_PATH = envConfig.path
22-
process.env.__AMAZONQLSP_UI = envConfig.ui
23-
},
24-
() => {
25-
delete process.env.__AMAZONQLSP_MANIFEST_URL
26-
delete process.env.__AMAZONQLSP_SUPPORTED_VERSIONS
27-
delete process.env.__AMAZONQLSP_ID
28-
delete process.env.__AMAZONQLSP_PATH
29-
delete process.env.__AMAZONQLSP_UI
30-
},
31-
],
32-
[
33-
'getAmazonQWorkspaceLspConfig',
34-
getAmazonQWorkspaceLspConfig,
35-
defaultAmazonQWorkspaceLspConfig,
36-
(envConfig: LspConfig) => {
37-
process.env.__AMAZONQWORKSPACELSP_MANIFEST_URL = envConfig.manifestUrl
38-
process.env.__AMAZONQWORKSPACELSP_SUPPORTED_VERSIONS = envConfig.supportedVersions
39-
process.env.__AMAZONQWORKSPACELSP_ID = envConfig.id
40-
process.env.__AMAZONQWORKSPACELSP_PATH = envConfig.path
41-
},
42-
() => {
43-
delete process.env.__AMAZONQWORKSPACELSP_MANIFEST_URL
44-
delete process.env.__AMAZONQWORKSPACELSP_SUPPORTED_VERSIONS
45-
delete process.env.__AMAZONQWORKSPACELSP_ID
46-
delete process.env.__AMAZONQWORKSPACELSP_PATH
47-
},
48-
],
49-
] as const) {
50-
describe(name, () => {
51-
let sandbox: sinon.SinonSandbox
52-
let serviceConfigStub: sinon.SinonStub
53-
const settingConfig: LspConfig = {
54-
manifestUrl: 'https://custom.url/manifest.json',
55-
supportedVersions: '4.0.0',
56-
id: 'AmazonQSetting',
57-
suppressPromptPrefix: config().suppressPromptPrefix,
58-
path: '/custom/path',
59-
...(name === 'getAmazonQLspConfig' && { ui: '/chat/client/location' }),
60-
}
11+
describe('getAmazonQLspConfig', () => {
12+
let sandbox: sinon.SinonSandbox
13+
let serviceConfigStub: sinon.SinonStub
14+
const settingConfig: ExtendedAmazonQLSPConfig = {
15+
manifestUrl: 'https://custom.url/manifest.json',
16+
supportedVersions: '4.0.0',
17+
id: 'AmazonQSetting',
18+
suppressPromptPrefix: getAmazonQLspConfig().suppressPromptPrefix,
19+
path: '/custom/path',
20+
ui: '/chat/client/location',
21+
}
6122

62-
beforeEach(() => {
63-
sandbox = sinon.createSandbox()
23+
beforeEach(() => {
24+
sandbox = sinon.createSandbox()
6425

65-
serviceConfigStub = sandbox.stub()
66-
sandbox.stub(DevSettings, 'instance').get(() => ({
67-
getServiceConfig: serviceConfigStub,
68-
}))
69-
})
26+
serviceConfigStub = sandbox.stub()
27+
sandbox.stub(DevSettings, 'instance').get(() => ({
28+
getServiceConfig: serviceConfigStub,
29+
}))
30+
})
7031

71-
afterEach(() => {
72-
sandbox.restore()
73-
resetEnv()
74-
})
32+
afterEach(() => {
33+
sandbox.restore()
34+
resetEnv()
35+
})
7536

76-
it('uses default config', () => {
77-
serviceConfigStub.returns({})
78-
assert.deepStrictEqual(config(), defaultConfig)
79-
})
37+
it('uses default config', () => {
38+
serviceConfigStub.returns({})
39+
assert.deepStrictEqual(getAmazonQLspConfig(), defaultAmazonQLspConfig)
40+
})
8041

81-
it('overrides path', () => {
82-
const path = '/custom/path/to/lsp'
83-
serviceConfigStub.returns({ path })
42+
it('overrides path', () => {
43+
const path = '/custom/path/to/lsp'
44+
serviceConfigStub.returns({ path })
8445

85-
assert.deepStrictEqual(config(), {
86-
...defaultConfig,
87-
path,
88-
})
46+
assert.deepStrictEqual(getAmazonQLspConfig(), {
47+
...defaultAmazonQLspConfig,
48+
path,
8949
})
50+
})
9051

91-
it('overrides default settings', () => {
92-
serviceConfigStub.returns(settingConfig)
52+
it('overrides default settings', () => {
53+
serviceConfigStub.returns(settingConfig)
9354

94-
assert.deepStrictEqual(config(), settingConfig)
95-
})
55+
assert.deepStrictEqual(getAmazonQLspConfig(), settingConfig)
56+
})
9657

97-
it('environment variable takes precedence over settings', () => {
98-
setEnv(settingConfig)
99-
serviceConfigStub.returns({})
100-
assert.deepStrictEqual(config(), settingConfig)
101-
})
58+
it('environment variable takes precedence over settings', () => {
59+
setEnv(settingConfig)
60+
serviceConfigStub.returns({})
61+
assert.deepStrictEqual(getAmazonQLspConfig(), settingConfig)
10262
})
103-
}
63+
64+
function setEnv(envConfig: ExtendedAmazonQLSPConfig) {
65+
process.env.__AMAZONQLSP_MANIFEST_URL = envConfig.manifestUrl
66+
process.env.__AMAZONQLSP_SUPPORTED_VERSIONS = envConfig.supportedVersions
67+
process.env.__AMAZONQLSP_ID = envConfig.id
68+
process.env.__AMAZONQLSP_PATH = envConfig.path
69+
process.env.__AMAZONQLSP_UI = envConfig.ui
70+
}
71+
72+
function resetEnv() {
73+
delete process.env.__AMAZONQLSP_MANIFEST_URL
74+
delete process.env.__AMAZONQLSP_SUPPORTED_VERSIONS
75+
delete process.env.__AMAZONQLSP_ID
76+
delete process.env.__AMAZONQLSP_PATH
77+
delete process.env.__AMAZONQLSP_UI
78+
}
79+
})

packages/core/src/amazonq/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export { ExtensionMessage } from '../amazonq/webview/ui/commands'
3737
export { CodeReference } from '../codewhispererChat/view/connector/connector'
3838
export { extractAuthFollowUp } from './util/authUtils'
3939
export { Messenger } from './commons/connector/baseMessenger'
40-
export * from './lsp/config'
4140
export * as secondaryAuth from '../auth/secondaryAuth'
4241
export * as authConnection from '../auth/connection'
4342
export * as featureConfig from './webview/generators/featureConfig'

packages/core/src/amazonq/lsp/config.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/core/src/shared/lsp/baseLspInstaller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as nodePath from 'path'
77
import vscode from 'vscode'
8-
import { LspConfig } from '../../amazonq/lsp/config'
98
import { LanguageServerResolver } from './lspResolver'
109
import { ManifestResolver } from './manifestResolver'
1110
import { LspResolution, ResourcePaths } from './types'
@@ -14,6 +13,14 @@ import { Range } from 'semver'
1413
import { getLogger } from '../logger/logger'
1514
import type { Logger, LogTopic } from '../logger/logger'
1615

16+
export interface LspConfig {
17+
manifestUrl: string
18+
supportedVersions: string
19+
id: string
20+
suppressPromptPrefix: string
21+
path?: string
22+
}
23+
1724
export abstract class BaseLspInstaller<T extends ResourcePaths = ResourcePaths, Config extends LspConfig = LspConfig> {
1825
private logger: Logger
1926

0 commit comments

Comments
 (0)