From 84fbf9bc87ca0168a19d557698b6f9fbe61b374e Mon Sep 17 00:00:00 2001 From: Yury Date: Wed, 28 Apr 2021 12:08:53 +0300 Subject: [PATCH] Release 1.0.1 Fix incorrect behavior of UI elements. Now they should appear correctly depending on the current active text editor. --- extension/CHANGELOG.md | 8 +++++- extension/package-lock.json | 4 +-- extension/package.json | 2 +- extension/src/extension.ts | 1 - .../src/features/status-bars/file-format.ts | 24 +++++++---------- .../src/features/status-bars/main-file.ts | 26 +++++++------------ extension/src/helpers.ts | 4 +-- 7 files changed, 31 insertions(+), 38 deletions(-) diff --git a/extension/CHANGELOG.md b/extension/CHANGELOG.md index eb0ffe9..1896a56 100644 --- a/extension/CHANGELOG.md +++ b/extension/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.1 + +This is a hotfix release. + +Fix incorrect behavior of UI elements. Now they should appear correctly depending on the current active text editor. + ## 1.0.0 -First public release. \ No newline at end of file +First public release. diff --git a/extension/package-lock.json b/extension/package-lock.json index 57cd313..9503663 100644 --- a/extension/package-lock.json +++ b/extension/package-lock.json @@ -1,12 +1,12 @@ { "name": "vs-api-contractor", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vs-api-contractor", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "dependencies": { "fs-extra": "^9.1.0", diff --git a/extension/package.json b/extension/package.json index 0e394a4..67f3051 100644 --- a/extension/package.json +++ b/extension/package.json @@ -3,7 +3,7 @@ "displayName": "API Contractor", "description": "Define, edit, validate and preview your API contracts in RAML and OpenAPI (Swagger)", "publisher": "deiteris", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "icon": "images/icon.png", "engines": { diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 00023c0..3b539e7 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -229,7 +229,6 @@ export async function activate(ctx: ExtensionContext) { ctx.subscriptions.push(client.start()) fileFormatStatusBar = new FileFormatStatusBar('API format of the current file.') - fileFormatStatusBar.changeApiFormat() ctx.subscriptions.push(fileFormatStatusBar) mainFileStatusBar = new MainFileStatusBar(ExtensionCommands.SetMainApiFile, 'Select root API file.', documentSelector) diff --git a/extension/src/features/status-bars/file-format.ts b/extension/src/features/status-bars/file-format.ts index 795b7e2..9d1e76e 100644 --- a/extension/src/features/status-bars/file-format.ts +++ b/extension/src/features/status-bars/file-format.ts @@ -1,4 +1,4 @@ -import { workspace, commands, window, StatusBarItem, StatusBarAlignment, Disposable } from 'vscode' +import { workspace, commands, window, StatusBarItem, StatusBarAlignment, Disposable, TextDocument } from 'vscode' import { readApiFileFormat } from '../../helpers' export class FileFormatStatusBar extends Disposable { @@ -11,6 +11,7 @@ export class FileFormatStatusBar extends Disposable { this.statusBarItem.tooltip = tooltip this.disposables.push(this.statusBarItem) + this.changeApiFormat(window.activeTextEditor?.document) this.registerEvents() } @@ -19,16 +20,16 @@ export class FileFormatStatusBar extends Disposable { } // TODO: FileFormatStatusBar controls the context on which preview buttons depends. This is not what normally should be expected... - async changeApiFormat() { - const apiFormat = await readApiFileFormat() + async changeApiFormat(document: TextDocument | undefined) { + const apiFormat = await readApiFileFormat(document) if (apiFormat) { commands.executeCommand('setContext', 'ac.isApiFile', true) this.updateText(`${apiFormat.type}`) this.show() - } else { - commands.executeCommand('setContext', 'ac.isApiFile', false) - this.hide() + return } + commands.executeCommand('setContext', 'ac.isApiFile', false) + this.hide() } show() { @@ -40,16 +41,11 @@ export class FileFormatStatusBar extends Disposable { } private registerEvents() { - this.disposables.push(workspace.onDidCloseTextDocument(async () => { - await this.changeApiFormat() + this.disposables.push(window.onDidChangeActiveTextEditor(async (editor) => { + await this.changeApiFormat(editor?.document) })) - - this.disposables.push(workspace.onDidOpenTextDocument(async () => { - await this.changeApiFormat() - })) - this.disposables.push(workspace.onDidSaveTextDocument(async () => { - await this.changeApiFormat() + await this.changeApiFormat(window.activeTextEditor?.document) })) } diff --git a/extension/src/features/status-bars/main-file.ts b/extension/src/features/status-bars/main-file.ts index a82d608..5733cf7 100644 --- a/extension/src/features/status-bars/main-file.ts +++ b/extension/src/features/status-bars/main-file.ts @@ -1,4 +1,4 @@ -import { workspace, window, StatusBarItem, StatusBarAlignment, Disposable, DocumentFilter } from 'vscode' +import { window, StatusBarItem, StatusBarAlignment, Disposable, DocumentFilter, TextDocument } from 'vscode' export class MainFileStatusBar extends Disposable { private statusBarItem: StatusBarItem @@ -13,6 +13,7 @@ export class MainFileStatusBar extends Disposable { this.statusBarItem.tooltip = tooltip this.disposables.push(this.statusBarItem) + this.toggle(window.activeTextEditor?.document) this.registerEvents() } @@ -20,26 +21,17 @@ export class MainFileStatusBar extends Disposable { this.statusBarItem.text = text } - show() { - this.statusBarItem.show() - } - - hide() { + toggle(document: TextDocument | undefined) { + if (document && this.documentFilter.some(filter => filter.language === document.languageId)) { + this.statusBarItem.show() + return + } this.statusBarItem.hide() } private registerEvents() { - this.disposables.push(workspace.onDidCloseTextDocument(async () => { - const document = window.activeTextEditor?.document - if (!document || !this.documentFilter.some(filter => filter.language === document.languageId)) { - this.statusBarItem.hide() - } - })) - this.disposables.push(workspace.onDidOpenTextDocument(async () => { - const document = window.activeTextEditor?.document - if (document && this.documentFilter.some(filter => filter.language === document.languageId)) { - this.statusBarItem.show() - } + this.disposables.push(window.onDidChangeActiveTextEditor(async (editor) => { + this.toggle(editor?.document) })) } diff --git a/extension/src/helpers.ts b/extension/src/helpers.ts index 1d1c4d0..f7b60cb 100644 --- a/extension/src/helpers.ts +++ b/extension/src/helpers.ts @@ -1,8 +1,8 @@ import * as child_process from "child_process" -import { window, workspace } from "vscode" +import { TextDocument, window, workspace } from "vscode" import { ApiSearch, ApiFormat } from "./features/api-search" -export async function readApiFileFormat(document = window.activeTextEditor?.document): Promise { +export async function readApiFileFormat(document: TextDocument | undefined): Promise { if (document && document.uri.scheme === 'file') { const workspaceRoot = workspace.rootPath if (!workspaceRoot) {