Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Mar 21, 2024
1 parent 31adac5 commit 8eed6d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
8 changes: 8 additions & 0 deletions extension/src/flow-cli/cli-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BehaviorSubject, Observable, distinctUntilChanged, pairwise, startWith
import { execDefault } from '../utils/shell/exec'
import { StateCache } from '../utils/state-cache'
import * as semver from 'semver'
import * as vscode from 'vscode'
import { Settings } from '../settings/settings'

const CHECK_FLOW_CLI_CMD = (flowCommand: string): string => `${flowCommand} version`
Expand Down Expand Up @@ -50,6 +51,13 @@ export class CliProvider {
return await this.#availableBinaries[name].getValue()
})

// Display warning to user if binary doesn't exist
this.#currentBinary$.subscribe((binary) => {
if (binary === null) {
void vscode.window.showErrorMessage(`The configured Flow CLI binary "${this.#selectedBinaryName.getValue()}" does not exist. Please check your settings.`)
}
})

// Subscribe to changes in the selected binary to update the caches
this.#selectedBinaryName.pipe(distinctUntilChanged(), startWith(null), pairwise()).subscribe(([prev, curr]) => {
// Swap out the cache for the selected binary
Expand Down
24 changes: 15 additions & 9 deletions extension/src/flow-cli/cli-selection-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { CliBinary, CliProvider } from './cli-provider'
import { SemVer } from 'semver'
import * as vscode from 'vscode'

const TOGGLE_CADENCE_VERSION_COMMAND = 'cadence.changeCadenceVersion'
const CHANGE_CADENCE_VERSION = 'cadence.changeCadenceVersion'
const CADENCE_V1_CLI_REGEX = /-cadence-v1.0.0/g
// label with icon
const GET_BINARY_LABEL = (version: SemVer): string => `Flow CLI v${version.format()}`

export class CliSelectionProvider implements vscode.Disposable {
Expand All @@ -18,28 +19,34 @@ export class CliSelectionProvider implements vscode.Disposable {
this.#cliProvider = cliProvider

// Register the command to toggle the version
vscode.commands.registerCommand(TOGGLE_CADENCE_VERSION_COMMAND, async () => await this.#toggleSelector(true))
vscode.commands.registerCommand(CHANGE_CADENCE_VERSION, async () => {
this.#cliProvider.refresh()
await this.#toggleSelector(true)
})

// Register UI components
zip(this.#cliProvider.currentBinary$, this.#cliProvider.availableBinaries$).subscribe(() => {
void this.#refreshSelector()
})
this.#cliProvider.currentBinary$.subscribe((binary) => {
if (binary === null) return
this.#statusBarItem?.dispose()
this.#statusBarItem = this.#createStatusBarItem(binary?.version)
this.#statusBarItem = this.#createStatusBarItem(binary?.version ?? null)
this.#statusBarItem.show()
})
}

#createStatusBarItem (version: SemVer): vscode.StatusBarItem {
#createStatusBarItem (version: SemVer | null): vscode.StatusBarItem {
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1)
statusBarItem.command = TOGGLE_CADENCE_VERSION_COMMAND
statusBarItem.command = CHANGE_CADENCE_VERSION
statusBarItem.color = new vscode.ThemeColor('statusBar.foreground')
statusBarItem.tooltip = 'Click to change the Flow CLI version'

// Update the status bar text when the version changes
statusBarItem.text = GET_BINARY_LABEL(version)
if (version) {
statusBarItem.text = GET_BINARY_LABEL(version)
} else {
statusBarItem.text = '$(error) Flow CLI not found'
statusBarItem.color = new vscode.ThemeColor('errorForeground')
}

return statusBarItem
}
Expand Down Expand Up @@ -79,7 +86,6 @@ export class CliSelectionProvider implements vscode.Disposable {
// Select the current binary
if (currentBinary !== null) {
const currentBinaryItem = versionSelector.items.find(item => item instanceof AvailableBinaryItem && item.path === currentBinary.name)
console.log(currentBinaryItem)
if (currentBinaryItem != null) {
versionSelector.selectedItems = [currentBinaryItem]
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/server/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class LanguageServerAPI {
await this.deactivate()

this.#isActive = true
await this.startClient()
await this.startClient().catch(() => {})
this.#subscribeToConfigChanges()
this.#subscribeToSettingsChanges()
}
Expand Down

0 comments on commit 8eed6d8

Please sign in to comment.