Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Nov 21, 2024
2 parents 06a3517 + 9a33598 commit 5d9130c
Show file tree
Hide file tree
Showing 10 changed files with 734 additions and 411 deletions.
73 changes: 54 additions & 19 deletions apps/nxls/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ process.on('uncaughtException', (e) => {

let WORKING_PATH: string | undefined = undefined;
let CLIENT_CAPABILITIES: ClientCapabilities | undefined = undefined;
let NXLS_TIMEOUT = false;
let unregisterFileWatcher: () => void = () => {
//noop
};
Expand All @@ -134,10 +135,11 @@ const documents = new TextDocuments(TextDocument);
documents.listen(connection);

connection.onInitialize(async (params) => {
keepAlive();
setLspLogger(connection);
lspLogger.log('Initializing Nx Language Server');

const { workspacePath } = params.initializationOptions ?? {};
const { workspacePath, nxlsTimeout } = params.initializationOptions ?? {};
try {
WORKING_PATH =
workspacePath ||
Expand All @@ -149,6 +151,8 @@ connection.onInitialize(async (params) => {
throw 'Unable to determine workspace path';
}

NXLS_TIMEOUT = nxlsTimeout || false;

loadRootEnvFiles(WORKING_PATH);

CLIENT_CAPABILITIES = params.capabilities;
Expand Down Expand Up @@ -213,6 +217,7 @@ connection.onInitialize(async (params) => {
});

connection.onCompletion(async (completionParams) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand Down Expand Up @@ -278,6 +283,7 @@ connection.onCompletion(async (completionParams) => {
});

connection.onHover(async (hoverParams) => {
keepAlive();
const hoverDocument = documents.get(hoverParams.textDocument.uri);

if (!hoverDocument) {
Expand All @@ -289,6 +295,7 @@ connection.onHover(async (hoverParams) => {
});

connection.onDefinition((definitionParams) => {
keepAlive();
const definitionDocument = documents.get(definitionParams.textDocument.uri);

if (!definitionDocument || !WORKING_PATH) {
Expand All @@ -301,6 +308,7 @@ connection.onDefinition((definitionParams) => {
});

connection.onDocumentLinks(async (params) => {
keepAlive();
const linkDocument = documents.get(params.textDocument.uri);

if (!linkDocument) {
Expand All @@ -324,11 +332,13 @@ connection.onDocumentLinks(async (params) => {
const jsonDocumentMapper = getLanguageModelCache();

documents.onDidClose((e) => {
keepAlive();
NativeWatcher.onCloseDocument(e.document.uri);
jsonDocumentMapper.onDocumentRemoved(e.document);
});

documents.onDidOpen(async (e) => {
keepAlive();
NativeWatcher.onOpenDocument(e.document.uri);
if (!e.document.uri.endsWith('project.json')) {
return;
Expand Down Expand Up @@ -367,12 +377,10 @@ connection.onShutdown(async () => {
}
});

connection.onExit(() => {
connection.dispose();
killTree(process.pid);
});
connection.onExit(exitHandler);

connection.onRequest(NxStopDaemonRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -381,6 +389,7 @@ connection.onRequest(NxStopDaemonRequest, async () => {
});

connection.onRequest(NxWorkspaceRequest, async ({ reset }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -389,6 +398,7 @@ connection.onRequest(NxWorkspaceRequest, async ({ reset }) => {
});

connection.onRequest(NxWorkspaceSerializedRequest, async ({ reset }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -398,12 +408,14 @@ connection.onRequest(NxWorkspaceSerializedRequest, async ({ reset }) => {
});

connection.onRequest(NxWorkspacePathRequest, () => {
keepAlive();
return WORKING_PATH;
});

connection.onRequest(
NxGeneratorsRequest,
async (args: { options?: NxGeneratorsRequestOptions }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -418,6 +430,7 @@ connection.onRequest(
connection.onRequest(
NxGeneratorOptionsRequest,
async (args: { options: NxGeneratorOptionsRequestOptions }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -437,6 +450,7 @@ connection.onRequest(
connection.onRequest(
NxProjectByPathRequest,
async (args: { projectPath: string }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -450,6 +464,7 @@ connection.onRequest(
connection.onRequest(
NxProjectsByPathsRequest,
async (args: { paths: string[] }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -463,6 +478,7 @@ connection.onRequest(
connection.onRequest(
NxProjectByRootRequest,
async (args: { projectRoot: string }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -473,23 +489,10 @@ connection.onRequest(
}
);

// TODO: REMOVE ONCE OLD GENERATE UI IS GONE
connection.onRequest(
NxGeneratorContextFromPathRequest,
async (args: { generator?: TaskExecutionSchema; path: string }) => {
if (!WORKING_PATH) {
return new ResponseError(
1000,
'Unable to get Nx info: no workspace path'
);
}
return getGeneratorContextFromPath(args.generator, args.path, WORKING_PATH);
}
);

connection.onRequest(
NxGeneratorContextV2Request,
async (args: { path: string | undefined }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -501,6 +504,7 @@ connection.onRequest(
);

connection.onRequest(NxVersionRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -509,13 +513,15 @@ connection.onRequest(NxVersionRequest, async () => {
});

connection.onRequest(NxProjectGraphOutputRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
return getProjectGraphOutput(WORKING_PATH);
});

connection.onRequest(NxCreateProjectGraphRequest, async ({ showAffected }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -528,6 +534,7 @@ connection.onRequest(NxCreateProjectGraphRequest, async ({ showAffected }) => {
});

connection.onRequest(NxProjectFolderTreeRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -537,6 +544,7 @@ connection.onRequest(NxProjectFolderTreeRequest, async () => {
connection.onRequest(
NxTransformedGeneratorSchemaRequest,
async (schema: GeneratorSchema) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -550,6 +558,7 @@ connection.onRequest(
connection.onRequest(
NxStartupMessageRequest,
async (schema: GeneratorSchema) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -561,13 +570,15 @@ connection.onRequest(
);

connection.onRequest(NxHasAffectedProjectsRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
return hasAffectedProjects(WORKING_PATH, lspLogger);
});

connection.onRequest(NxSourceMapFilesToProjectsMapRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -577,6 +588,7 @@ connection.onRequest(NxSourceMapFilesToProjectsMapRequest, async () => {
connection.onRequest(
NxTargetsForConfigFileRequest,
async (args: { projectName: string; configFilePath: string }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(
1000,
Expand All @@ -592,27 +604,31 @@ connection.onRequest(
);

connection.onRequest(NxCloudStatusRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
return getNxCloudStatus(WORKING_PATH);
});

connection.onRequest(NxCloudOnboardingInfoRequest, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
return getCloudOnboardingInfo(WORKING_PATH);
});

connection.onRequest(NxPDVDataRequest, async (args: { filePath: string }) => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
}
return getPDVData(WORKING_PATH, args.filePath);
});

connection.onNotification(NxWorkspaceRefreshNotification, async () => {
keepAlive();
if (!WORKING_PATH) {
return new ResponseError(1001, 'Unable to get Nx info: no workspace path');
}
Expand All @@ -623,6 +639,7 @@ connection.onNotification(NxWorkspaceRefreshNotification, async () => {
connection.onNotification(
'workspace/didCreateFiles',
async (createdFiles: CreateFilesParams) => {
keepAlive();
if (!createdFiles.files.some((f) => f.uri.endsWith('project.json'))) {
return;
}
Expand All @@ -641,6 +658,7 @@ connection.onNotification(
connection.onNotification(
'workspace/didDeleteFiles',
async (deletedFiles: DeleteFilesParams) => {
keepAlive();
if (!deletedFiles.files.some((f) => f.uri.endsWith('project.json'))) {
return;
}
Expand All @@ -657,6 +675,7 @@ connection.onNotification(
);

connection.onNotification(NxChangeWorkspace, async (workspacePath) => {
keepAlive();
WORKING_PATH = workspacePath;
loadRootEnvFiles(WORKING_PATH);

Expand Down Expand Up @@ -724,3 +743,19 @@ function getJsonDocument(document: TextDocument) {

ensureOnlyJsonRpcStdout();
connection.listen();

function exitHandler() {
connection.dispose();
killTree(process.pid);
}

let timeout: NodeJS.Timeout | undefined;

function keepAlive() {
if (timeout) {
clearTimeout(timeout);
}
if (NXLS_TIMEOUT) {
timeout = setTimeout(exitHandler, 1000 * 60 * 60 * 3 /* 3 hours */);
}
}
4 changes: 2 additions & 2 deletions apps/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { initNxConfigDecoration } from '@nx-console/vscode/nx-config-decoration'
import { initNxConversion } from '@nx-console/vscode/nx-conversion';
import { initHelpAndFeedbackView } from '@nx-console/vscode/nx-help-and-feedback-view';
import { initVscodeProjectGraph } from '@nx-console/vscode/project-graph';
import { enableTypeScriptPlugin } from '@nx-console/vscode/typescript-plugin';
import { initTypeScriptServerPlugin } from '@nx-console/vscode/typescript-plugin';

import {
NxStopDaemonRequest,
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function activate(c: ExtensionContext) {
context.subscriptions.push(manuallySelectWorkspaceDefinitionCommand);
await registerSettingsNxWorkspacePathWatcher();

await enableTypeScriptPlugin(context);
await initTypeScriptServerPlugin(context);
watchCodeLensConfigChange(context);

getTelemetry().logUsage('extension-activate', {
Expand Down
Loading

0 comments on commit 5d9130c

Please sign in to comment.