Skip to content

Commit

Permalink
cleanup, remove setTimeout updates for now
Browse files Browse the repository at this point in the history
not sure if it make a huge difference
  • Loading branch information
jasonlyu123 committed Sep 9, 2023
1 parent 742fec2 commit c5f560e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
9 changes: 4 additions & 5 deletions packages/language-server/src/lib/documents/DocumentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
*/
export class DocumentManager {
private emitter = new EventEmitter();
// private openedInClient: FileSet;
private documents: FileMap<Document>;
private locked: FileSet;
private deleteCandidates: FileSet;
Expand Down Expand Up @@ -67,10 +66,10 @@ export class DocumentManager {
}

markAsOpenedInClient(uri: string): void {
// const document = this.documents.get(normalizeUri(uri));
// if (document) {
// document.openedByClient = true;
// }
const document = this.documents.get(normalizeUri(uri));
if (document) {
document.openedByClient = true;
}
}

getAllOpenedByClient() {
Expand Down
24 changes: 7 additions & 17 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ const configFileModifiedTime = new FileMap<Date | undefined>();
const configFileForOpenFiles = new FileMap<string>();
const pendingReloads = new FileSet();

process.on('exit', () => {
// so that the schedule update doesn't keep the process open
forAllServices((service) => service.dispose());
});

/**
* For testing only: Reset the cache for services.
* Try to refactor this some day so that this file provides
Expand Down Expand Up @@ -175,6 +170,7 @@ export async function getServiceForTsconfig(
Logger.log('Reloading ts service at ', tsconfigPath, ' due to config updated');
} else {
Logger.log('Initialize new ts service at ', tsconfigPath);
console.trace();
}

pendingReloads.delete(tsconfigPath);
Expand Down Expand Up @@ -267,7 +263,6 @@ async function createLanguageService(
let languageServiceReducedMode = false;
let projectVersion = 0;
let dirty = false;
let timer: NodeJS.Timeout | undefined;

const getCanonicalFileName = createGetCanonicalFileName(tsSystem.useCaseSensitiveFileNames);

Expand Down Expand Up @@ -427,6 +422,7 @@ async function createLanguageService(

function updateProjectFiles(): void {
projectVersion++;
dirty = true;
const projectFileCountBefore = snapshotManager.getProjectFileNames().length;
snapshotManager.updateProjectFiles();
const projectFileCountAfter = snapshotManager.getProjectFileNames().length;
Expand Down Expand Up @@ -630,7 +626,6 @@ async function createLanguageService(
}

function dispose() {
clearTimeout(timer);
languageService.dispose();
snapshotManager.dispose();
configWatchers.get(tsconfigPath)?.close();
Expand Down Expand Up @@ -704,10 +699,6 @@ async function createLanguageService(
}

function updateIfDirty() {
if (timer) {
clearTimeout(timer);
timer = undefined;
}
if (!dirty) {
return;
}
Expand All @@ -719,14 +710,13 @@ async function createLanguageService(
}

function scheduleUpdate() {
projectVersion++;
dirty = true;

if (timer) {
clearTimeout(timer);
if (dirty) {
return;
}

timer = setTimeout(updateIfDirty, 1000);
projectVersion++;
dirty = true;
console.log('scheduleUpdate');
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ export function startServer(options?: LSOptions) {

connection.onDidOpenTextDocument((evt) => {
const document = docManager.openClientDocument(evt.textDocument);
docManager.markAsOpenedInClient(evt.textDocument.uri);
diagnosticsManager.scheduleUpdate(document);
});

Expand Down
1 change: 0 additions & 1 deletion packages/language-server/src/svelte-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export class SvelteCheck {
text: doc.text,
uri: doc.uri
});
this.docManager.markAsOpenedInClient(doc.uri);
}
}

Expand Down

0 comments on commit c5f560e

Please sign in to comment.