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 Dec 16, 2024
2 parents 0113634 + 714fb4a commit 8eff692
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dev.nx.console.nxls.NxlsService
import dev.nx.console.nxls.server.requests.NxGeneratorOptionsRequestOptions
import dev.nx.console.settings.NxConsoleProjectSettingsProvider
import dev.nx.console.settings.options.GeneratorFilter
import dev.nx.console.utils.Notifier
import dev.nx.console.utils.nxlsWorkingPath
import java.awt.Dimension
import javax.swing.ListSelectionModel.SINGLE_SELECTION
Expand Down Expand Up @@ -61,20 +62,16 @@ class NxGenerateService(val project: Project, private val cs: CoroutineScope) {
}
}

suspend fun selectGenerator(
actionEvent: AnActionEvent?,
) = suspendCoroutine {
suspend fun selectGenerator(actionEvent: AnActionEvent?) = suspendCoroutine {
cs.launch {
val generators = getFilteredGenerators()

if (generators.isEmpty()) {
it.resume(null)
}
val generatorNames = generators.map { it.name }
val hasErrors =
(NxlsService.getInstance(project).workspace()?.errors?.size ?: 0) > 0
Notifier.notifyNoGenerators(project, hasErrors)

if (generatorNames.size == 1) {
val chosenGenerator = generators.find { g -> g.name == generatorNames[0] }
it.resume(chosenGenerator)
return@launch it.resume(null)
}

val popup =
Expand Down Expand Up @@ -111,7 +108,7 @@ class NxGenerateService(val project: Project, private val cs: CoroutineScope) {
project: Project,
generator: NxGenerator,
contextPath: String? = null,
options: List<NxGeneratorOption>? = null
options: List<NxGeneratorOption>? = null,
) {
val generatorOptions =
options
Expand All @@ -121,7 +118,7 @@ class NxGenerateService(val project: Project, private val cs: CoroutineScope) {
NxGeneratorOptionsRequestOptions(
generator.data.collection,
generator.data.name,
generator.schemaPath
generator.schemaPath,
)
)

Expand All @@ -132,7 +129,7 @@ class NxGenerateService(val project: Project, private val cs: CoroutineScope) {
.service<NxlsService>()
.generatorContextFromPath(
generatorWithOptions,
contextPath?.let { nxlsWorkingPath(contextPath) }
contextPath?.let { nxlsWorkingPath(contextPath) },
)

ApplicationManager.getApplication().invokeLater {
Expand All @@ -141,7 +138,7 @@ class NxGenerateService(val project: Project, private val cs: CoroutineScope) {
renderer.openGenerateUi(
project,
NxGenerator(generator = generatorWithOptions, contextValues = generatorContext),
RunGeneratorManager(project)
RunGeneratorManager(project),
)
}
}
Expand Down
33 changes: 26 additions & 7 deletions apps/intellij/src/main/kotlin/dev/nx/console/utils/Notifier.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.nx.console.utils

import com.intellij.analysis.problemsView.toolWindow.ProblemsView
import com.intellij.ide.BrowserUtil
import com.intellij.ide.util.PropertiesComponent
import com.intellij.notification.*
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -111,13 +113,8 @@ class Notifier {
)
.setTitle("Nx Console")
.addAction(
object : NotificationAction("Learn more") {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
BrowserUtil.browse(
"https://plugins.jetbrains.com/docs/intellij/jcef.html"
)
notification.expire()
}
NotificationAction.createSimpleExpiring("Learn more") {
BrowserUtil.browse("https://plugins.jetbrains.com/docs/intellij/jcef.html")
}
)
.notify(project)
Expand Down Expand Up @@ -157,6 +154,28 @@ class Notifier {
return notification
}

fun notifyNoGenerators(project: Project, hasNxErrors: Boolean) {
val notification =
getGroup()
.createNotification(
if (hasNxErrors) "No generators found. View Nx Errors for more information."
else "No generators found. View logs for more information.",
NotificationType.ERROR,
)
.setTitle("Nx Console")

if (hasNxErrors) {
notification.addAction(
NotificationAction.createSimpleExpiring("View Nx Errors") {
ProblemsView.getToolWindow(project)?.show()
}
)
} else {
notification.addAction(ActionManager.getInstance().getAction("OpenLog"))
}
notification.notify(project)
}

fun notifyAnything(
project: Project,
message: String,
Expand Down
4 changes: 2 additions & 2 deletions apps/nxls-e2e/src/nxls-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
StreamMessageWriter,
} from 'vscode-languageserver/node';

import { killTree } from '@nx-console/shared/utils';
import { defaultVersion } from './utils';
import { killGroup } from '@nx-console/shared/utils';

export class NxlsWrapper {
private cwd?: string;
Expand Down Expand Up @@ -147,7 +147,7 @@ export class NxlsWrapper {

if (this.process?.pid) {
try {
killTree(this.process.pid, 'SIGKILL');
killGroup(this.process.pid);
} catch (e) {
console.log(`NXLS WRAPPER: ${e}`);
}
Expand Down
36 changes: 21 additions & 15 deletions apps/nxls/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
completionHandler,
configureSchemaForProject,
configureSchemas,
getCompletionItems,
projectSchemaIsRegistered,
resetInferencePluginsCompletionCache,
} from '@nx-console/language-server/capabilities/code-completion';
Expand Down Expand Up @@ -44,7 +43,6 @@ import {
getJsonLanguageService,
getLanguageModelCache,
lspLogger,
mergeArrays,
setLspLogger,
} from '@nx-console/language-server/utils';
import {
Expand Down Expand Up @@ -80,13 +78,8 @@ import {
} from '@nx-console/language-server/workspace';
import { GeneratorSchema } from '@nx-console/shared/generate-ui-types';
import { NxWorkspace } from '@nx-console/shared/types';
import { formatError, killTree } from '@nx-console/shared/utils';
import { dirname, relative } from 'node:path';
import {
ClientCapabilities,
CompletionList,
TextDocument,
} from 'vscode-json-languageservice';
import { formatError, killGroup } from '@nx-console/shared/utils';
import { ClientCapabilities, TextDocument } from 'vscode-json-languageservice';
import {
CreateFilesParams,
DeleteFilesParams,
Expand Down Expand Up @@ -148,7 +141,6 @@ connection.onInitialize(async (params) => {
CLIENT_CAPABILITIES = params.capabilities;

await configureSchemas(WORKING_PATH, CLIENT_CAPABILITIES);

unregisterFileWatcher = await languageServerWatcher(
WORKING_PATH,
async () => {
Expand Down Expand Up @@ -300,11 +292,6 @@ connection.onShutdown(async () => {
jsonDocumentMapper.dispose();
});

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

connection.onRequest(NxStopDaemonRequest, async () => {
if (!WORKING_PATH) {
return new ResponseError(1000, 'Unable to get Nx info: no workspace path');
Expand Down Expand Up @@ -663,4 +650,23 @@ function getJsonDocument(document: TextDocument) {
}

ensureOnlyJsonRpcStdout();

const exitHandler = () => {
process.off('SIGTERM', exitHandler);

try {
connection.dispose();
} catch (e) {
// noop
}

if (process.connected) {
process.disconnect();
}

killGroup(process.pid);
};
process.on('SIGTERM', exitHandler);

connection.onExit(exitHandler);
connection.listen();
17 changes: 13 additions & 4 deletions apps/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Disposable,
ExtensionContext,
ExtensionMode,
ProgressLocation,
RelativePattern,
commands,
tasks,
Expand All @@ -13,7 +14,7 @@ import {

import {
checkIsNxWorkspace,
killTree,
killGroup,
withTimeout,
} from '@nx-console/shared/utils';
import {
Expand All @@ -34,7 +35,11 @@ import {
registerVscodeAddDependency,
} from '@nx-console/vscode/add-dependency';
import { initGenerateUiWebview } from '@nx-console/vscode/generate-ui-webview';
import { createNxlsClient, getNxlsClient } from '@nx-console/vscode/lsp-client';
import {
createNxlsClient,
getNxlsClient,
showRefreshLoadingAtLocation,
} from '@nx-console/vscode/lsp-client';
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';
Expand Down Expand Up @@ -81,6 +86,10 @@ export async function activate(c: ExtensionContext) {
initTelemetry(context.extensionMode === ExtensionMode.Production);
initNxInit(context);

context.subscriptions.push(
showRefreshLoadingAtLocation(ProgressLocation.Window)
);

initHelpAndFeedbackView(context);
const manuallySelectWorkspaceDefinitionCommand = commands.registerCommand(
'nxConsole.selectWorkspaceManually',
Expand Down Expand Up @@ -137,12 +146,12 @@ export async function deactivate() {

const nxlsPid = getNxlsClient()?.getNxlsPid();
if (nxlsPid) {
killTree(nxlsPid, 'SIGINT');
killGroup(nxlsPid);
}

getTelemetry().logUsage('extension-deactivate');

killTree(process.pid, 'SIGTERM');
killGroup(process.pid);
}

// -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getNxWorkspaceConfig(
nxVersion: NxVersion,
logger: Logger
): Promise<{
projectGraph: ProjectGraph;
projectGraph: ProjectGraph | undefined;
sourceMaps: ConfigurationSourceMaps | undefined;
nxJson: NxJsonConfiguration;
projectFileMap: ProjectFileMap | undefined;
Expand Down
5 changes: 4 additions & 1 deletion libs/language-server/workspace/src/lib/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ async function _workspace(
const isLerna = await fileExists(join(workspacePath, 'lerna.json'));

return {
projectGraph,
projectGraph: projectGraph ?? {
nodes: {},
dependencies: {},
},
sourceMaps,
nxJson,
projectFileMap,
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export { checkIsNxWorkspace } from './lib/check-is-nx-workspace';
export { getNxExecutionCommand } from './lib/get-nx-execution-command';
export * from './lib/parse-target-string';
export * from './lib/utils';
export * from './lib/kill-tree';
export * from './lib/cipe';
export * from './lib/package-manager-command';
export * from './lib/kill-group';
17 changes: 17 additions & 0 deletions libs/shared/utils/src/lib/kill-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { execSync } from 'child_process';

export function killGroup(pid: number, signal: NodeJS.Signals = 'SIGTERM') {
if (process.platform === 'win32') {
try {
execSync('taskkill /pid ' + pid + ' /T /F', {
windowsHide: true,
});
} catch (err: any) {
if (err?.status !== 128) {
throw err;
}
}
} else {
process.kill(-pid, signal);
}
}
Loading

0 comments on commit 8eff692

Please sign in to comment.