Skip to content
Closed
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
13 changes: 11 additions & 2 deletions packages/amazonq/src/lsp/lspInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as nodeFs from 'fs'

Check failure on line 6 in packages/amazonq/src/lsp/lspInstaller.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

'fs' import is restricted from being used. Avoid node:fs and use shared/fs/fs.ts when possible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason of using nodeFs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fs wrapper in the toolkit doesn't have existsSync, but Node.js's native fs module does

import vscode from 'vscode'
import { fs, getNodeExecutableName, getRgExecutableName, BaseLspInstaller, ResourcePaths } from 'aws-core-vscode/shared'
import path from 'path'
Expand Down Expand Up @@ -45,11 +46,15 @@

const nodePath = path.join(assetDirectory, `servers/${getNodeExecutableName()}`)
const rgPath = path.join(assetDirectory, `servers/ripgrep/${getRgExecutableName()}`)
// Check for amazonq-ui.js in both locations for backwards compatibility
const amazonqUiInClientsPath = path.join(assetDirectory, 'clients/amazonq-ui.js')
const amazonqUiInServersPath = path.join(assetDirectory, 'servers/amazonq-ui.js')
const uiPath = nodeFs.existsSync(amazonqUiInClientsPath) ? amazonqUiInClientsPath : amazonqUiInServersPath
return {
lsp: path.join(assetDirectory, 'servers/aws-lsp-codewhisperer.js'),
node: nodePath,
ripGrep: rgPath,
ui: path.join(assetDirectory, 'clients/amazonq-ui.js'),
ui: uiPath,
}
}

Expand All @@ -58,10 +63,14 @@

export function getBundledResourcePaths(ctx: vscode.ExtensionContext): AmazonQResourcePaths {
const assetDirectory = vscode.Uri.joinPath(ctx.extensionUri, 'resources', 'language-server').fsPath
// Check for amazonq-ui.js in both locations for backwards compatibility
const amazonqUiInClientsPath = path.join(assetDirectory, 'clients/amazonq-ui.js')
const amazonqUiInServersPath = path.join(assetDirectory, 'servers/amazonq-ui.js')
const uiPath = nodeFs.existsSync(amazonqUiInClientsPath) ? amazonqUiInClientsPath : amazonqUiInServersPath
return {
lsp: path.join(assetDirectory, 'servers', 'aws-lsp-codewhisperer.js'),
node: process.execPath,
ripGrep: '',
ui: path.join(assetDirectory, 'clients', 'amazonq-ui.js'),
ui: uiPath,
}
}
3 changes: 2 additions & 1 deletion packages/core/src/shared/lsp/baseLspInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export abstract class BaseLspInstaller<T extends ResourcePaths = ResourcePaths,
// resourcePaths = {
// lsp = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/aws-lsp-codewhisperer.js'
// node = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/node'
// ui = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/clients/amazonq-ui.js'
// ui = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/clients/amazonq-ui.js' or
// '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/amazonq-ui.js'
// }
// ```
resourcePaths: this.resourcePaths(assetDirectory),
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/shared/lsp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export interface LspResult {
* resourcePaths = {
* lsp = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/aws-lsp-codewhisperer.js'
* node = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/node'
* ui = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/clients/amazonq-ui.js'
* ui = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/clients/amazonq-ui.js' or
* '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/amazonq-ui.js'
* }
* ```
*/
Expand All @@ -47,7 +48,8 @@ export interface LspResolution<T extends ResourcePaths> extends LspResult {
* resourcePaths = {
* lsp = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/aws-lsp-codewhisperer.js'
* node = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/node'
* ui = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/clients/amazonq-ui.js'
* ui = '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/clients/amazonq-ui.js' or
* '<cachedir>/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/amazonq-ui.js'
* }
* ```
*/
Expand Down
5 changes: 4 additions & 1 deletion scripts/lspArtifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ export async function downloadLanguageServer(): Promise<void> {
if (!fs.existsSync(path.join(resourcesDir, 'servers', 'aws-lsp-codewhisperer.js'))) {
throw new Error(`Extracting aws-lsp-codewhisperer.js failure`)
}
if (!fs.existsSync(path.join(resourcesDir, 'clients', 'amazonq-ui.js'))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to make it compatible with https://github.com/aws/aws-toolkit-vscode/pull/7421/files. Please check function export function getBundledResourcePaths(ctx: vscode.ExtensionContext): AmazonQResourcePaths {

// Check for amazonq-ui.js in both locations for backwards compatibility (moved from clients.zip to servers.zip)
const amazonqUiInClients = fs.existsSync(path.join(resourcesDir, 'clients', 'amazonq-ui.js'))
const amazonqUiInServers = fs.existsSync(path.join(resourcesDir, 'servers', 'amazonq-ui.js'))
if (!amazonqUiInClients && !amazonqUiInServers) {
throw new Error(`Extracting amazonq-ui.js failure`)
}
console.log('Download and extraction completed successfully')
Expand Down
Loading