Skip to content

Commit

Permalink
fix(vscode): support only ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Oct 27, 2022
1 parent 71d53cd commit e0c9541
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/typescript-explorer-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
"editor/context": [
{
"command": "typescriptExplorer.selection.select",
"group": "type-explorer"
"group": "type-explorer",
"when": "editorLangId == 'typescript' || editorLangId == 'javascript'"
}
]
},
Expand Down
11 changes: 10 additions & 1 deletion packages/typescript-explorer-vscode/src/state/stateManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TypeInfo } from "@ts-type-explorer/api"
import * as vscode from "vscode"
import { selectionEnabled } from "../config"
import { getQuickInfoAtPosition, showError } from "../util"
import { getQuickInfoAtPosition, isDocumentSupported, showError } from "../util"
import { TypeTreeItem, TypeTreeProvider } from "../view/typeTreeView"
import { ViewProviders } from "../view/views"

Expand Down Expand Up @@ -37,6 +37,10 @@ export class StateManager {
)

vscode.window.onDidChangeTextEditorSelection((e) => {
if (!isDocumentSupported(e.textEditor.document)) {
return
}

if (
e.kind === vscode.TextEditorSelectionChangeKind.Command ||
!e.kind
Expand Down Expand Up @@ -98,6 +102,11 @@ export class StateManager {
return
}

if (!isDocumentSupported(editor.document)) {
showError("Document language not supported!")
return
}

this.selectTypeAtPosition(
editor.document.fileName,
[editor.selection],
Expand Down
4 changes: 4 additions & 0 deletions packages/typescript-explorer-vscode/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ export function smartlySetConfigValue<T>(
export function showError(message: string) {
vscode.window.showErrorMessage(message)
}

export function isDocumentSupported({ languageId }: vscode.TextDocument) {
return languageId === "typescript" || languageId === "javascript"
}

0 comments on commit e0c9541

Please sign in to comment.