Skip to content

Commit

Permalink
Start the 'indexedVersion' at -1 to prevent an issue where a document…
Browse files Browse the repository at this point in the history
… may skip the 'indexing' process.
  • Loading branch information
EliotVU committed Jul 23, 2024
1 parent 8041708 commit 9956fa5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/src/UC/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function removeChildren(scope: UCStructSymbol) {
}

export type DocumentParseData = {
context: ProgramContext;
context: ProgramContext | undefined;
parser: UCParser;
};

Expand All @@ -77,7 +77,7 @@ export class UCDocument {
public readonly uri: DocumentUri;

/** The current indexed TextDocument's version as reported by the client. */
public indexedVersion = 0;
public indexedVersion = -1;

// TODO: Displace this with a DiagnosticCollection visitor.
public nodes: IDiagnosticNode[] = [];
Expand Down
9 changes: 8 additions & 1 deletion server/src/UC/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ export const documentsCodeIndexed$ = new Subject<UCDocument[]>();
export function indexDocument(document: UCDocument, text?: string): void {
const buildStart = performance.now();
let buildTime: number;
let indexedVersion: number | undefined;

if (typeof text === 'undefined') {
// Let's fetch the text from the file system, but first see if we have an active text document (this ensures we retrieve the latest revision)
const textDocument = ActiveTextDocuments.get(document.uri);
text = textDocument?.getText() ?? readTextByURI(document.uri);
if (textDocument) {
text = textDocument.getText();
indexedVersion = textDocument.version;
} else {
text = readTextByURI(document.uri);
}
}

try {
Expand All @@ -98,6 +104,7 @@ export function indexDocument(document: UCDocument, text?: string): void {
const indexer = new DocumentSymbolIndexer(document);
// We set this here to prevent any re-triggering within the following indexing process.
document.hasBeenIndexed = true;
if (indexedVersion) document.indexedVersion = indexedVersion;
document.accept(indexer);
} catch (err) {
console.error(
Expand Down
12 changes: 7 additions & 5 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
createPackage,
createPackageByDir,
documentBuilt$,
documentIndexed$,
documentsCodeIndexed$,
enumerateDocuments,
getDocumentById,
Expand Down Expand Up @@ -432,6 +433,7 @@ connection.onInitialized((params) => {
if (process.env.NODE_ENV === 'development') {
connection.console.log(`Document "${document.fileName}" is already indexed.`);
}

return;
}

Expand Down Expand Up @@ -503,7 +505,7 @@ connection.onInitialized((params) => {
queueIndexDocument(globalUci);
}

// Weird, even if when we have "zero" active documents, this will array is filled?
// Weird, even if when we have "zero" active documents, this array is filled?
const activeDocuments = ActiveTextDocuments
.all()
.map(doc => getDocumentByURI(doc.uri))
Expand Down Expand Up @@ -735,11 +737,8 @@ async function registerPresetsWorkspace(generation: UCGeneration, licensee: UELi
};
}

// Always include the 'Shared' presets
const presetsPath = path.join(__dirname, 'presets');
const folders: WorkspaceFolder[] = [
pathToWorkspaceFolder(path.join(presetsPath, 'Shared'))
];
const folders: WorkspaceFolder[] = [];

switch (generation) {
case UCGeneration.UC1:
Expand All @@ -762,6 +761,9 @@ async function registerPresetsWorkspace(generation: UCGeneration, licensee: UELi
break;
}

// Always include the 'Shared' presets, included as last so that they cannot not precede any of the licensee or generation specific documents of the same name.
folders.push(pathToWorkspaceFolder(path.join(presetsPath, 'Shared')));

// blob search all the files in the presets folder!
const workspaceFiles = await getWorkspaceFiles(folders, 'presets');

Expand Down

0 comments on commit 9956fa5

Please sign in to comment.