-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcb2438
commit b351230
Showing
37 changed files
with
1,131 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as vscode from 'vscode' | ||
|
||
import { getOriginalFileUri, isTmpFileUri } from './file-utils/create-tmp-file' | ||
import { VsCodeFS } from './file-utils/vscode-fs' | ||
import { logger } from './logger' | ||
|
||
let isHandlingEditorChange = false | ||
|
||
const openCorrespondingFiles = async (tmpUri: vscode.Uri): Promise<void> => { | ||
if (isHandlingEditorChange || !isTmpFileUri(tmpUri)) return | ||
isHandlingEditorChange = true | ||
const originalUri = getOriginalFileUri(tmpUri) | ||
|
||
try { | ||
// check if the original file exists | ||
await VsCodeFS.stat(originalUri.fsPath) | ||
|
||
// open original file | ||
const originalDocument = | ||
await vscode.workspace.openTextDocument(originalUri) | ||
await vscode.window.showTextDocument( | ||
originalDocument, | ||
vscode.ViewColumn.One | ||
) | ||
|
||
// 重新聚焦到 .aide.vue 文件 | ||
// refocus on the .aide file | ||
const tmpDocument = await vscode.workspace.openTextDocument(tmpUri) | ||
await vscode.window.showTextDocument(tmpDocument, vscode.ViewColumn.Two) | ||
} catch (e) { | ||
logger.warn('openCorrespondingFiles error', e) | ||
} finally { | ||
isHandlingEditorChange = false | ||
} | ||
} | ||
|
||
export const autoOpenCorrespondingFiles = ( | ||
context: vscode.ExtensionContext | ||
) => { | ||
context.subscriptions.push( | ||
vscode.workspace.onDidOpenTextDocument(async document => { | ||
const maybeTmpUri = document.uri | ||
if (isTmpFileUri(maybeTmpUri)) { | ||
await openCorrespondingFiles(maybeTmpUri) | ||
} | ||
}) | ||
) | ||
|
||
context.subscriptions.push( | ||
vscode.window.onDidChangeActiveTextEditor(editor => { | ||
const maybeTmpUri = editor?.document.uri | ||
if (maybeTmpUri && isTmpFileUri(maybeTmpUri) && !isHandlingEditorChange) { | ||
openCorrespondingFiles(maybeTmpUri) | ||
} | ||
}) | ||
) | ||
} |
File renamed without changes.
Oops, something went wrong.