fix(vscode): skip stale active editor broadcasts (#1246)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
58c6a22036
commit
2c25bfc8d7
@@ -389,30 +389,38 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const view = this._view;
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (!editor || editor.document.uri.scheme !== 'file') {
|
if (!editor || editor.document.uri.scheme !== 'file') {
|
||||||
this._scheduleClearActiveEditorFile();
|
this._scheduleClearActiveEditorFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editorUri = editor.document.uri;
|
||||||
|
const editorUriKey = editorUri.toString();
|
||||||
|
|
||||||
if (this._clearActiveEditorFileTimer !== undefined) {
|
if (this._clearActiveEditorFileTimer !== undefined) {
|
||||||
clearTimeout(this._clearActiveEditorFileTimer);
|
clearTimeout(this._clearActiveEditorFileTimer);
|
||||||
this._clearActiveEditorFileTimer = undefined;
|
this._clearActiveEditorFileTimer = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filePath = normalizeWindowsDriveLetter(editor.document.uri.fsPath);
|
const filePath = normalizeWindowsDriveLetter(editorUri.fsPath);
|
||||||
const rawFileName = editor.document.uri.fsPath;
|
const rawFileName = editorUri.fsPath;
|
||||||
const fileName = rawFileName.replace(/\\/g, '/').split('/').pop() || '';
|
const fileName = rawFileName.replace(/\\/g, '/').split('/').pop() || '';
|
||||||
const relativePath = vscode.workspace.asRelativePath(editor.document.uri, false);
|
const relativePath = vscode.workspace.asRelativePath(editorUri, false);
|
||||||
|
|
||||||
let fileSize: number | null = null;
|
let fileSize: number | null = null;
|
||||||
try {
|
try {
|
||||||
const stat = await vscode.workspace.fs.stat(editor.document.uri);
|
const stat = await vscode.workspace.fs.stat(editorUri);
|
||||||
fileSize = stat.size;
|
fileSize = stat.size;
|
||||||
} catch {
|
} catch {
|
||||||
// File may not be saved yet or inaccessible
|
// File may not be saved yet or inaccessible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._view !== view || vscode.window.activeTextEditor?.document.uri.toString() !== editorUriKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let selection: { startLine: number; endLine: number; text: string } | null = null;
|
let selection: { startLine: number; endLine: number; text: string } | null = null;
|
||||||
if (!editor.selection.isEmpty) {
|
if (!editor.selection.isEmpty) {
|
||||||
selection = {
|
selection = {
|
||||||
@@ -428,7 +436,7 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
|||||||
}
|
}
|
||||||
this._lastActiveEditorFilePayload = payload;
|
this._lastActiveEditorFilePayload = payload;
|
||||||
|
|
||||||
this._view.webview.postMessage({
|
view.webview.postMessage({
|
||||||
type: 'command',
|
type: 'command',
|
||||||
command: 'activeEditorFile',
|
command: 'activeEditorFile',
|
||||||
payload,
|
payload,
|
||||||
|
|||||||
Reference in New Issue
Block a user