Merge pull request #153 from github/cschleiden/time-operations
Time LS operations
This commit is contained in:
@@ -26,6 +26,7 @@ import {onCompletion} from "./on-completion";
|
|||||||
import {ReadFileRequest, Requests} from "./request";
|
import {ReadFileRequest, Requests} from "./request";
|
||||||
import {fetchActionMetadata} from "./utils/action-metadata";
|
import {fetchActionMetadata} from "./utils/action-metadata";
|
||||||
import {TTLCache} from "./utils/cache";
|
import {TTLCache} from "./utils/cache";
|
||||||
|
import {timeOperation} from "./utils/timer";
|
||||||
import {valueProviders} from "./value-providers";
|
import {valueProviders} from "./value-providers";
|
||||||
|
|
||||||
export function initConnection(connection: Connection) {
|
export function initConnection(connection: Connection) {
|
||||||
@@ -93,7 +94,7 @@ export function initConnection(connection: Connection) {
|
|||||||
// The content of a text document has changed. This event is emitted
|
// The content of a text document has changed. This event is emitted
|
||||||
// when the text document first opened or when its content has changed.
|
// when the text document first opened or when its content has changed.
|
||||||
documents.onDidChangeContent(change => {
|
documents.onDidChangeContent(change => {
|
||||||
validateTextDocument(change.document);
|
return timeOperation("validation", async () => await validateTextDocument(change.document));
|
||||||
});
|
});
|
||||||
|
|
||||||
async function validateTextDocument(textDocument: TextDocument): Promise<void> {
|
async function validateTextDocument(textDocument: TextDocument): Promise<void> {
|
||||||
@@ -113,28 +114,34 @@ export function initConnection(connection: Connection) {
|
|||||||
return await connection.sendRequest(Requests.ReadFile, {path} satisfies ReadFileRequest);
|
return await connection.sendRequest(Requests.ReadFile, {path} satisfies ReadFileRequest);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
const result = await validate(textDocument, config);
|
|
||||||
|
|
||||||
connection.sendDiagnostics({uri: textDocument.uri, diagnostics: result});
|
const result = await validate(textDocument, config);
|
||||||
|
await connection.sendDiagnostics({uri: textDocument.uri, diagnostics: result});
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.onCompletion(async ({position, textDocument}: TextDocumentPositionParams): Promise<CompletionItem[]> => {
|
connection.onCompletion(async ({position, textDocument}: TextDocumentPositionParams): Promise<CompletionItem[]> => {
|
||||||
return await onCompletion(
|
return timeOperation(
|
||||||
connection,
|
"completion",
|
||||||
position,
|
async () =>
|
||||||
documents.get(textDocument.uri)!,
|
await onCompletion(
|
||||||
client,
|
connection,
|
||||||
repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)),
|
position,
|
||||||
cache
|
documents.get(textDocument.uri)!,
|
||||||
|
client,
|
||||||
|
repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)),
|
||||||
|
cache
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.onHover(async ({position, textDocument}: HoverParams): Promise<Hover | null> => {
|
connection.onHover(async ({position, textDocument}: HoverParams): Promise<Hover | null> => {
|
||||||
const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri));
|
return timeOperation("hover", async () => {
|
||||||
|
const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri));
|
||||||
|
|
||||||
return hover(documents.get(textDocument.uri)!, position, {
|
return await hover(documents.get(textDocument.uri)!, position, {
|
||||||
descriptionProvider: descriptionProvider(client, cache),
|
descriptionProvider: descriptionProvider(client, cache),
|
||||||
contextProviderConfig: repoContext && contextProviders(client, repoContext, cache)
|
contextProviderConfig: repoContext && contextProviders(client, repoContext, cache)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import {log} from "@github/actions-languageservice/log";
|
||||||
|
|
||||||
|
export function timeOperation<T>(name: string, f: () => T): T {
|
||||||
|
const start = Date.now();
|
||||||
|
const result = f();
|
||||||
|
const end = Date.now();
|
||||||
|
|
||||||
|
log(`${name} took ${end - start}ms`);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -43,6 +43,16 @@ export function setLogLevel(ll: LogLevel) {
|
|||||||
logLevel = ll;
|
logLevel = ll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function log(message: string): void {
|
||||||
|
if (logLevel > LogLevel.Debug) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const l of loggers) {
|
||||||
|
l.log(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function info(message: string): void {
|
export function info(message: string): void {
|
||||||
if (logLevel > LogLevel.Info) {
|
if (logLevel > LogLevel.Info) {
|
||||||
return;
|
return;
|
||||||
@@ -72,9 +82,3 @@ export function error(message: string): void {
|
|||||||
l.error(message);
|
l.error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function log(message: string): void {
|
|
||||||
for (const l of loggers) {
|
|
||||||
l.log(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user