diff --git a/src/commands/LanguageServerInfoCommand.spec.ts b/src/commands/LanguageServerInfoCommand.spec.ts index 5e389d8f..511dd72b 100644 --- a/src/commands/LanguageServerInfoCommand.spec.ts +++ b/src/commands/LanguageServerInfoCommand.spec.ts @@ -73,7 +73,8 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }]); }); @@ -91,7 +92,8 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }]); }); @@ -101,11 +103,13 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }, { label: `Use Workspace Version`, description: '1.2.3', - detail: 'node_modules/brighterscript' + detail: 'node_modules/brighterscript', + value: 'node_modules/brighterscript' }]); }); @@ -115,11 +119,13 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }, { label: `Use Workspace Version`, description: '1.2.3', - detail: 'node_modules/brighterscript' + detail: 'node_modules/brighterscript', + value: 'node_modules/brighterscript' }]); writePackage('2.3.4'); @@ -127,11 +133,13 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }, { label: `Use Workspace Version`, description: '2.3.4', - detail: 'node_modules/brighterscript' + detail: 'node_modules/brighterscript', + value: 'node_modules/brighterscript' }]); }); @@ -141,11 +149,13 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }, { label: `Use Workspace Version`, description: '1.2.3', - detail: 'node_modules/brighterscript' + detail: 'node_modules/brighterscript', + value: 'node_modules/brighterscript' }]); fsExtra.removeSync(`${tempDir}/node_modules`); @@ -153,7 +163,8 @@ describe('LanguageServerInfoCommand', () => { command['discoverBrighterScriptVersions']([tempDir]) ).to.eql([{ label: `Use VSCode's version`, - description: embeddedBscVersion + description: embeddedBscVersion, + value: 'embedded' }]); }); }); diff --git a/src/commands/LanguageServerInfoCommand.ts b/src/commands/LanguageServerInfoCommand.ts index 484acaa5..0ee61aaf 100644 --- a/src/commands/LanguageServerInfoCommand.ts +++ b/src/commands/LanguageServerInfoCommand.ts @@ -9,16 +9,21 @@ import { VscodeCommand } from './VscodeCommand'; import URI from 'vscode-uri'; import * as relativeTime from 'dayjs/plugin/relativeTime'; import { util } from '../util'; -import type { LocalPackageManager } from '../managers/LocalPackageManager'; +import { type LocalPackageManager } from '../managers/LocalPackageManager'; +import * as semver from 'semver'; import { standardizePath as s } from 'brighterscript'; -import * as dayjs from 'dayjs'; import type { QuickPickItem } from 'vscode'; +import * as dayjs from 'dayjs'; dayjs.extend(relativeTime); export class LanguageServerInfoCommand { public static commandName = 'extension.brightscript.languageServer.info'; + public localPackageManager: LocalPackageManager; + public register(context: vscode.ExtensionContext, localPackageManager: LocalPackageManager) { + this.localPackageManager = localPackageManager; + context.subscriptions.push(vscode.commands.registerCommand(LanguageServerInfoCommand.commandName, async () => { const commands = [{ label: `Change Selected BrighterScript Version`, @@ -164,11 +169,30 @@ export class LanguageServerInfoCommand { description: '', detail: '', command: async () => { - let versionsFromNpm: QuickPickItemEnhanced[] = (await versionsFromNpmPromise).map(x => ({ - label: x.version, - value: x.version, - description: dayjs(x.date).fromNow(true) + ' ago' - })); + let versionsFromNpm: QuickPickItemEnhanced[] = (await versionsFromNpmPromise).filter(x => !semver.prerelease(x.version)).map(x => { + return { + label: x.version, + value: x.version, + description: `${dayjs(x.date).fromNow(true)} ago` + }; + }); + return await vscode.window.showQuickPick(versionsFromNpm, { placeHolder: `Select the BrighterScript version used for BrightScript and BrighterScript language features` }) as any; + } + } as any); + + //get the full list of versions from npm + quickPickItems.push({ + label: '$(package) Install from npm (insider builds)', + description: '', + detail: '', + command: async () => { + let versionsFromNpm: QuickPickItemEnhanced[] = (await versionsFromNpmPromise).filter(x => semver.prerelease(x.version)).map(x => { + return { + label: x.version, + value: x.version, + description: `${dayjs(x.date).fromNow(true)} ago` + }; + }); return await vscode.window.showQuickPick(versionsFromNpm, { placeHolder: `Select the BrighterScript version used for BrightScript and BrighterScript language features` }) as any; } } as any); diff --git a/src/managers/LocalPackageManager.spec.ts b/src/managers/LocalPackageManager.spec.ts index cb976b90..f4da7cc4 100644 --- a/src/managers/LocalPackageManager.spec.ts +++ b/src/managers/LocalPackageManager.spec.ts @@ -309,15 +309,15 @@ describe('LocalPackageManager', () => { }); describe('getVersionDirName', () => { - it('fetches the catalog when not supplied', async () => { + it('fetches the catalog when not supplied', () => { expect( - await manager['getVersionDirName']('brighterscript', '1.0.0') + manager['getVersionDirName']('brighterscript', '1.0.0') ).to.eql('1.0.0'); }); - it('creates a hash', async () => { + it('creates a hash', () => { expect( - await manager['getVersionDirName']('brighterscript', packageUrl) + manager['getVersionDirName']('brighterscript', packageUrl) ).to.eql(md5(packageUrl)); }); @@ -333,12 +333,12 @@ describe('LocalPackageManager', () => { //ask for the dir name, it should come back with the hash of the packageUrl expect( - await manager['getVersionDirName']('brighterscript', packageUrl2) + manager['getVersionDirName']('brighterscript', packageUrl2) ).to.eql(md5(packageUrl)); //now ask for the dir name, it should come with a number appended to it since that hash already exists expect( - await manager['getVersionDirName']('brighterscript', packageUrl) + manager['getVersionDirName']('brighterscript', packageUrl) ).to.eql(`${md5(packageUrl)}-1`); }); });