Skip to content

Commit 725dc2b

Browse files
committed
fix(vscode): drop deleted files from discovery
Exclude clean open buffers whose files no longer exist from workspace scans and document validation so refresh cannot resurrect deleted GTS entries. Preserve dirty buffers until their edits are resolved, and remove stale registry entries when deleted buffers are closed. Signed-off-by: Artifizer <artifizer@gmail.com>
1 parent 2987934 commit 725dc2b

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎apps/vscode-extension/src/extension.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { rebuildRegistry, indexFile as indexFileInRegistry, removeFile as remove
88
import { getWorkspaceIgnore, resetWorkspaceIgnore, isGitIgnored, type FolderIgnore } from './gitignore'
99
import { WorkspaceLayoutStorage } from './storage'
1010
import { initValidation, resetValidationDiagnostics, validateOpenDocument, validateWorkspaceInBackground, revalidateDependents, onValidationCompleted } from './validation'
11-
import { isGtsCandidateFile } from './helpers'
11+
import { isGtsCandidateFile, isIndexableGtsDocument } from './helpers'
1212
import { GtsLinkProvider } from './linkProvider'
1313
import { registerGtsExplorer, type GtsExplorer } from './gtsExplorer'
1414
import type { LayoutSaveRequest, LayoutTarget, LayoutSnapshot } from '@gts/layout-storage'
@@ -559,17 +559,15 @@ export async function activate(context: vscode.ExtensionContext) {
559559
function collectOpenGtsPaths(): string[] {
560560
const ordered: string[] = []
561561
const seen = new Set<string>()
562-
const add = (fsPath: string) => {
562+
const add = (doc: vscode.TextDocument) => {
563+
if (!isIndexableGtsDocument(doc)) return
564+
const fsPath = doc.uri.fsPath
563565
if (!seen.has(fsPath)) { seen.add(fsPath); ordered.push(fsPath) }
564566
}
565567
const active = vscode.window.activeTextEditor?.document
566-
if (active && active.uri.scheme === 'file' && isGtsCandidateFile(active)) add(active.uri.fsPath)
567-
for (const ed of vscode.window.visibleTextEditors) {
568-
if (ed.document.uri.scheme === 'file' && isGtsCandidateFile(ed.document)) add(ed.document.uri.fsPath)
569-
}
570-
for (const d of vscode.workspace.textDocuments) {
571-
if (d.uri.scheme === 'file' && isGtsCandidateFile(d)) add(d.uri.fsPath)
572-
}
568+
if (active) add(active)
569+
for (const ed of vscode.window.visibleTextEditors) add(ed.document)
570+
for (const d of vscode.workspace.textDocuments) add(d)
573571
return ordered
574572
}
575573

‎apps/vscode-extension/src/helpers.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode'
2+
import * as fs from 'fs'
23
import { isGtsCandidateFileName } from '@gts/shared'
34

45
export function isGtsCandidateFile(document: vscode.TextDocument): boolean {
@@ -11,3 +12,7 @@ export function isGtsCandidateFile(document: vscode.TextDocument): boolean {
1112
document.languageId === 'jsonc' ||
1213
isGtsCandidateFileName(document.fileName)
1314
}
15+
16+
export function isIndexableGtsDocument(document: vscode.TextDocument): boolean {
17+
return isGtsCandidateFile(document) && (document.isDirty || fs.existsSync(document.uri.fsPath))
18+
}

‎apps/vscode-extension/src/validation.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as jsonc from 'jsonc-parser'
55
import { ValidationError, DEFAULT_GTS_CONFIG, parseGtsFileContent, isYamlFileName } from '@gts/shared'
66
import type { JsonRegistry, JsonSchema, JsonObj } from '@gts/shared'
77
import { getLastScanFiles } from './scanStore'
8-
import { getRegistry, rebuildRegistry, indexFile, getMalformedIds, getPathsWithMalformedIds } from './registryStore'
8+
import { getRegistry, rebuildRegistry, indexFile, removeFile, getMalformedIds, getPathsWithMalformedIds } from './registryStore'
99
import { malformedGtsIdMessage } from './gtsIdFormat'
10-
import { isGtsCandidateFile } from './helpers'
10+
import { isGtsCandidateFile, isIndexableGtsDocument } from './helpers'
1111

1212
let diagnosticCollection: vscode.DiagnosticCollection
1313
let workspaceDiagnosticCollection: vscode.DiagnosticCollection
@@ -509,7 +509,7 @@ function findValueRangeJson(parsed: ParsedDocument, segments: Array<string | num
509509
* Validate a document and update diagnostics
510510
*/
511511
export async function validateOpenDocument(document: vscode.TextDocument) {
512-
if (!isGtsCandidateFile(document)) {
512+
if (!isIndexableGtsDocument(document)) {
513513
return
514514
}
515515

@@ -882,7 +882,7 @@ async function validateClosedFile(filePath: string, index?: DefinitionIndex): Pr
882882
* When an editor closes, any unsaved buffer edits are discarded, so the registry
883883
* may still hold the stale live content that `validateOpenDocument` indexed. Re-
884884
* indexing from disk makes the subsequent closed-file validation reflect what is
885-
* actually on disk. No-op for non-file schemes or unreadable/deleted files.
885+
* actually on disk. Deleted or unreadable files are removed from the registry.
886886
*/
887887
async function reindexClosedFileFromDisk(uri: vscode.Uri): Promise<void> {
888888
if (uri.scheme !== 'file') return
@@ -894,8 +894,7 @@ async function reindexClosedFileFromDisk(uri: vscode.Uri): Promise<void> {
894894
try { content = parseGtsFileContent(name, text) } catch { content = text }
895895
indexFile(uri.fsPath, name, content)
896896
} catch {
897-
// File may have been deleted/renamed; leave the registry as-is so the
898-
// watcher's delete handler can drop it.
897+
removeFile(uri.fsPath)
899898
}
900899
}
901900

0 commit comments

Comments
 (0)