From 68bf6b97c561ed7251ea61e4e73790c39fd28d84 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 16 Apr 2024 07:59:55 -0700 Subject: [PATCH] rename & fix global configuration --- .../installers/flow-cli-installer.ts | 2 +- extension/src/flow-cli/cli-provider.ts | 24 +++++++++++-------- .../src/flow-cli/cli-selection-provider.ts | 2 +- ...s-provider.ts => cli-versions-provider.ts} | 2 +- extension/src/server/language-server.ts | 2 +- .../integration/1 - language-server.test.ts | 2 +- extension/test/unit/parser.test.ts | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) rename extension/src/flow-cli/{binary-versions-provider.ts => cli-versions-provider.ts} (99%) diff --git a/extension/src/dependency-installer/installers/flow-cli-installer.ts b/extension/src/dependency-installer/installers/flow-cli-installer.ts index 81dee013..fa8f971b 100644 --- a/extension/src/dependency-installer/installers/flow-cli-installer.ts +++ b/extension/src/dependency-installer/installers/flow-cli-installer.ts @@ -6,7 +6,7 @@ import { Installer, InstallerConstructor, InstallerContext } from '../installer' import * as semver from 'semver' import fetch from 'node-fetch' import { HomebrewInstaller } from './homebrew-installer' -import { KNOWN_FLOW_COMMANDS } from '../../flow-cli/binary-versions-provider' +import { KNOWN_FLOW_COMMANDS } from '../../flow-cli/cli-versions-provider' // Command to check flow-cli const COMPATIBLE_FLOW_CLI_VERSIONS = '>=1.6.0' diff --git a/extension/src/flow-cli/cli-provider.ts b/extension/src/flow-cli/cli-provider.ts index 963c456b..dd9bdb39 100644 --- a/extension/src/flow-cli/cli-provider.ts +++ b/extension/src/flow-cli/cli-provider.ts @@ -3,23 +3,23 @@ import { StateCache } from '../utils/state-cache' import * as vscode from 'vscode' import { Settings } from '../settings/settings' import { isEqual } from 'lodash' -import { CliBinary, BinaryVersionsProvider, KNOWN_FLOW_COMMANDS } from './binary-versions-provider' +import { CliBinary, CliVersionsProvider, KNOWN_FLOW_COMMANDS } from './cli-versions-provider' export class CliProvider { #selectedBinaryName: BehaviorSubject #currentBinary$: StateCache - #binaryVersionsProvider: BinaryVersionsProvider + #cliVersionsProvider: CliVersionsProvider #settings: Settings constructor (settings: Settings) { const initialBinaryPath = settings.getSettings().flowCommand this.#settings = settings - this.#binaryVersionsProvider = new BinaryVersionsProvider([initialBinaryPath]) + this.#cliVersionsProvider = new CliVersionsProvider([initialBinaryPath]) this.#selectedBinaryName = new BehaviorSubject(initialBinaryPath) this.#currentBinary$ = new StateCache(async () => { const name: string = this.#selectedBinaryName.getValue() - const versionCache = this.#binaryVersionsProvider.get(name) + const versionCache = this.#cliVersionsProvider.get(name) if (versionCache == null) return null return await versionCache.getValue() }) @@ -43,10 +43,10 @@ export class CliProvider { // Subscribe to changes in the selected binary to update the caches this.#selectedBinaryName.pipe(distinctUntilChanged(), startWith(null), pairwise()).subscribe(([prev, curr]) => { // Remove the previous binary from the cache - if (prev != null) this.#binaryVersionsProvider.remove(prev) + if (prev != null) this.#cliVersionsProvider.remove(prev) // Add the current binary to the cache - if (curr != null) this.#binaryVersionsProvider.add(curr) + if (curr != null) this.#cliVersionsProvider.add(curr) // Invalidate the current binary cache this.#currentBinary$.invalidate() @@ -58,7 +58,11 @@ export class CliProvider { } async setCurrentBinary (name: string): Promise { - await this.#settings.updateSettings({ flowCommand: name }) + if (vscode.workspace.workspaceFolders == null) { + await this.#settings.updateSettings({ flowCommand: name }, vscode.ConfigurationTarget.Global) + } else { + await this.#settings.updateSettings({ flowCommand: name }) + } } get currentBinary$ (): Observable { @@ -66,15 +70,15 @@ export class CliProvider { } async getBinaryVersions (): Promise { - return await this.#binaryVersionsProvider.getVersions() + return await this.#cliVersionsProvider.getVersions() } get binaryVersions$ (): Observable { - return this.#binaryVersionsProvider.versions$.pipe(distinctUntilChanged(isEqual)) + return this.#cliVersionsProvider.versions$.pipe(distinctUntilChanged(isEqual)) } // Refresh all cached binary versions refresh (): void { - this.#binaryVersionsProvider.refresh() + this.#cliVersionsProvider.refresh() } } diff --git a/extension/src/flow-cli/cli-selection-provider.ts b/extension/src/flow-cli/cli-selection-provider.ts index 4fd2df59..999f6f46 100644 --- a/extension/src/flow-cli/cli-selection-provider.ts +++ b/extension/src/flow-cli/cli-selection-provider.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode' import { zip } from 'rxjs' import { CliProvider } from './cli-provider' import { SemVer } from 'semver' -import { CliBinary } from './binary-versions-provider' +import { CliBinary } from './cli-versions-provider' const CHANGE_CLI_BINARY = 'cadence.changeFlowCliBinary' const CADENCE_V1_CLI_REGEX = /-cadence-v1.0.0/g diff --git a/extension/src/flow-cli/binary-versions-provider.ts b/extension/src/flow-cli/cli-versions-provider.ts similarity index 99% rename from extension/src/flow-cli/binary-versions-provider.ts rename to extension/src/flow-cli/cli-versions-provider.ts index ac2bb01f..c10d97c0 100644 --- a/extension/src/flow-cli/binary-versions-provider.ts +++ b/extension/src/flow-cli/cli-versions-provider.ts @@ -25,7 +25,7 @@ interface FlowVersionOutput { version: string } -export class BinaryVersionsProvider { +export class CliVersionsProvider { #rootCache: StateCache #caches: { [key: string]: StateCache } = {} diff --git a/extension/src/server/language-server.ts b/extension/src/server/language-server.ts index 30f3afaa..ad74ca80 100644 --- a/extension/src/server/language-server.ts +++ b/extension/src/server/language-server.ts @@ -7,7 +7,7 @@ import { BehaviorSubject, Subscription, filter, firstValueFrom, skip } from 'rxj import { envVars } from '../utils/shell/env-vars' import { FlowConfig } from './flow-config' import { CliProvider } from '../flow-cli/cli-provider' -import { KNOWN_FLOW_COMMANDS } from '../flow-cli/binary-versions-provider' +import { KNOWN_FLOW_COMMANDS } from '../flow-cli/cli-versions-provider' // Identities for commands handled by the Language server const RELOAD_CONFIGURATION = 'cadence.server.flow.reloadConfiguration' diff --git a/extension/test/integration/1 - language-server.test.ts b/extension/test/integration/1 - language-server.test.ts index befb0fd6..47c9ab36 100644 --- a/extension/test/integration/1 - language-server.test.ts +++ b/extension/test/integration/1 - language-server.test.ts @@ -9,7 +9,7 @@ import { BehaviorSubject, Subject } from 'rxjs' import { State } from 'vscode-languageclient' import * as sinon from 'sinon' import { SemVer } from 'semver' -import { CliBinary } from '../../src/flow-cli/binary-versions-provider' +import { CliBinary } from '../../src/flow-cli/cli-versions-provider' suite('Language Server & Emulator Integration', () => { let LS: LanguageServerAPI diff --git a/extension/test/unit/parser.test.ts b/extension/test/unit/parser.test.ts index 760542c6..5f5e9ec8 100644 --- a/extension/test/unit/parser.test.ts +++ b/extension/test/unit/parser.test.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import { parseFlowCliVersion } from '../../src/flow-cli/binary-versions-provider' +import { parseFlowCliVersion } from '../../src/flow-cli/cli-versions-provider' import { execDefault } from '../../src/utils/shell/exec' import { ASSERT_EQUAL } from '../globals' import * as semver from 'semver'