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 18, 2024
2 parents 2f2cdee + 8935212 commit 3656692
Show file tree
Hide file tree
Showing 22 changed files with 623 additions and 63 deletions.
26 changes: 13 additions & 13 deletions .nx/workflows/agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ launch-templates:
image: 'windows-2022'
init-steps:
- name: Checkout
uses: 'nrwl/nx-cloud-workflows/v3.6/workflow-steps/checkout/main.yaml'
uses: 'nrwl/nx-cloud-workflows/v4/workflow-steps/checkout/main.yaml'
- name: Restore Node Modules Cache
uses: 'nrwl/nx-cloud-workflows/v3.6/workflow-steps/cache/main.yaml'
env:
KEY: 'package-lock.json|yarn.lock|pnpm-lock.yaml'
PATHS: 'node_modules'
BASE_BRANCH: 'main'
uses: 'nrwl/nx-cloud-workflows/v4/workflow-steps/cache/main.yaml'
inputs:
key: 'package-lock.json|yarn.lock|pnpm-lock.yaml'
paths: 'node_modules'
base-branch: 'main'
- name: Restore Browser Binary Cache
uses: 'nrwl/nx-cloud-workflows/v3.6/workflow-steps/cache/main.yaml'
env:
KEY: 'package-lock.json|yarn.lock|pnpm-lock.yaml|"browsers"'
PATHS: |
uses: 'nrwl/nx-cloud-workflows/v4/workflow-steps/cache/main.yaml'
inputs:
key: 'package-lock.json|yarn.lock|pnpm-lock.yaml|"browsers"'
paths: |
'../.cache/Cypress'
'../.cache/ms-playwright'
BASE_BRANCH: 'main'
base-branch: 'main'
- name: Install Node Modules
uses: 'nrwl/nx-cloud-workflows/v3.6/workflow-steps/install-node-modules/main.yaml'
uses: 'nrwl/nx-cloud-workflows/v4/workflow-steps/install-node-modules/main.yaml'
- name: Install Browsers (if needed)
uses: 'nrwl/nx-cloud-workflows/v3.6/workflow-steps/install-browsers/main.yaml'
uses: 'nrwl/nx-cloud-workflows/v4/workflow-steps/install-browsers/main.yaml'
- name: Install cypress with --force
script: npx cypress install --force
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.intellij.util.messages.Topic
import com.intellij.util.ui.JBUI
import dev.nx.console.nx_toolwindow.tree.NxProjectsTree
import dev.nx.console.nx_toolwindow.tree.NxTreeStructure
import dev.nx.console.nxls.NxRefreshWorkspaceAction
import dev.nx.console.nxls.NxRefreshWorkspaceService
import dev.nx.console.nxls.NxWorkspaceRefreshListener
import dev.nx.console.nxls.NxlsService
Expand Down Expand Up @@ -326,7 +325,12 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
}

override fun actionPerformed(e: AnActionEvent) {
NxRefreshWorkspaceAction().actionPerformed(e)
TelemetryService.getInstance(project)
.featureUsed(
TelemetryEvent.MISC_REFRESH_WORKSPACE,
mapOf("source" to TelemetryEventSource.PROJECTS_VIEW),
)
NxRefreshWorkspaceService.getInstance(project).refreshWorkspace()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import dev.nx.console.models.NxVersion
import dev.nx.console.nxls.NxRefreshWorkspaceAction
import dev.nx.console.nxls.NxRefreshWorkspaceService
import dev.nx.console.telemetry.TelemetryEvent
import dev.nx.console.telemetry.TelemetryEventSource
import dev.nx.console.telemetry.TelemetryService
Expand Down Expand Up @@ -59,7 +59,7 @@ class ProjectDetailsEditorWithPreview(private val project: Project, file: Virtua
TelemetryEvent.MISC_REFRESH_WORKSPACE,
mapOf("source" to TelemetryEventSource.EDITOR_TOOLBAR),
)
NxRefreshWorkspaceAction().actionPerformed(e)
NxRefreshWorkspaceService.getInstance(project).refreshWorkspace()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { readFileSync } from 'fs';
import { join } from 'path';
import { Position } from 'vscode-languageserver';
import { URI } from 'vscode-uri';
import { NxlsWrapper } from '../nxls-wrapper';
import { e2eCwd, modifyJsonFile, newWorkspace, uniq } from '../utils';

let nxlsWrapper: NxlsWrapper;
const workspaceName = uniq('workspace');

const projectJsonPath = join(
e2eCwd,
workspaceName,
'apps',
workspaceName,
'project.json'
);

describe('namedInput link completion - default', () => {
beforeAll(async () => {
newWorkspace({
name: workspaceName,
options: {
preset: 'next',
},
});
nxlsWrapper = new NxlsWrapper(true);
await nxlsWrapper.startNxls(join(e2eCwd, workspaceName));

nxlsWrapper.sendNotification({
method: 'textDocument/didOpen',
params: {
textDocument: {
uri: URI.file(projectJsonPath).toString(),
languageId: 'JSON',
version: 1,
text: readFileSync(projectJsonPath, 'utf-8'),
},
},
});
});
afterAll(async () => {
await nxlsWrapper.stopNxls();
});
describe('named input links', () => {
it('should return correct target link for input if it is a namedInput in nx.json', async () => {
modifyJsonFile(projectJsonPath, (data) => ({
...data,
targets: {
build: {
inputs: ['default'],
},
},
}));

nxlsWrapper.sendNotification({
method: 'textDocument/didChange',
params: {
textDocument: {
uri: URI.file(projectJsonPath).toString(),
languageId: 'JSON',
version: 2,
},
contentChanges: [
{
text: readFileSync(projectJsonPath, 'utf-8'),
},
],
},
});

const linkResponse = await nxlsWrapper.sendRequest({
method: 'textDocument/documentLink',
params: {
textDocument: {
uri: URI.file(projectJsonPath).toString(),
},
position: Position.create(0, 1),
},
});

const defaultLine =
readFileSync(join(e2eCwd, workspaceName, 'nx.json'), 'utf-8')
.split('\n')
.findIndex((line) => line.includes('"default":')) + 1;

const targetLink = (linkResponse.result as any[])[0].target;
expect(targetLink).toMatch(new RegExp(`#${defaultLine}$`));
expect(decodeURI(targetLink)).toContain(join(workspaceName, 'nx.json'));
});

it('should not return target link for input if it is not a namedInput in nx.json', async () => {
modifyJsonFile(projectJsonPath, (data) => ({
...data,
targets: {
build: {
inputs: ['src/file.js', 'other'],
},
},
}));

nxlsWrapper.sendNotification({
method: 'textDocument/didChange',
params: {
textDocument: {
uri: URI.file(projectJsonPath).toString(),
languageId: 'JSON',
version: 2,
},
contentChanges: [
{
text: readFileSync(projectJsonPath, 'utf-8'),
},
],
},
});

const linkResponse = await nxlsWrapper.sendRequest({
method: 'textDocument/documentLink',
params: {
textDocument: {
uri: URI.file(projectJsonPath).toString(),
},
position: Position.create(0, 1),
},
});

const targetLinks = linkResponse.result as any[];
expect(targetLinks.length).toBe(0);
});

it('should return correct target link for named input within nx.json', async () => {
const nxJsonPath = join(e2eCwd, workspaceName, 'nx.json');
modifyJsonFile(nxJsonPath, (data) => ({
...data,
namedInputs: {
default: ['one', 'two'],
one: ['src/file.js'],
},
}));

nxlsWrapper.sendNotification({
method: 'textDocument/didOpen',
params: {
textDocument: {
uri: URI.file(nxJsonPath).toString(),
languageId: 'JSON',
version: 0,
text: readFileSync(nxJsonPath, 'utf-8'),
},
},
});

const linkResponse = await nxlsWrapper.sendRequest({
method: 'textDocument/documentLink',
params: {
textDocument: {
uri: URI.file(nxJsonPath).toString(),
},
position: Position.create(0, 1),
},
});

const oneLine =
readFileSync(nxJsonPath, 'utf-8')
.split('\n')
.findIndex((line) => line.includes('"one": [')) + 1;

const targetLink = (linkResponse.result as any[])[0].target;
expect(targetLink).toMatch(new RegExp(`#${oneLine}$`));
expect(decodeURI(targetLink)).toContain(join(workspaceName, 'nx.json'));
});
});
});
11 changes: 11 additions & 0 deletions apps/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@
"command": "nxCloud.showRunInApp",
"when": "view == nxCloudRecentCIPE && viewItem == run",
"group": "inline@1"
},
{
"command": "nxConsole.showProblems",
"when": "view == nxProjects && viewItem == projectGraphError",
"group": "inline@1"
}
],
"editor/title": [
Expand Down Expand Up @@ -652,6 +657,12 @@
"title": "Open Workspace in Browser",
"command": "nxCloud.openApp",
"icon": "$(cloud)"
},
{
"category": "Nx",
"title": "Show Nx Errors in Problems View",
"command": "nxConsole.showProblems",
"icon": "$(eye)"
}
],
"configuration": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
getDefaultCompletionType,
isArrayNode,
lspLogger,
} from '@nx-console/language-server/utils';
import {
CompletionType,
Expand Down Expand Up @@ -132,12 +133,15 @@ function completionItems(
return targetsCompletion(workingPath, node, document, true);
}
case CompletionType.inputName: {
lspLogger.log(`inputName completion ${node.value}`);
return inputNameCompletion(workingPath, node, document);
}
case CompletionType.inputNameWithDeps: {
lspLogger.log(`inputNameWithDeps completion ${node.value}`);
return inputNameCompletion(workingPath, node, document, true);
}
case CompletionType.inferencePlugins: {
lspLogger.log(`inferencePlugins completion ${node.value}`);
return inferencePluginsCompletion(workingPath);
}
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export async function inferencePluginsCompletion(
.split('node_modules/')
.pop();

inferencePluginsCompletion.push({
label: `${dependencyPath}/plugin`,
});
if (dependencyPath?.includes('nx')) {
inferencePluginsCompletion.push({
label: `${dependencyPath}/plugin`,
});
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from 'vscode-json-languageservice';
import { createRange } from './create-range';
import { targetLink } from './target-link';
import { namedInputLink } from './named-input-link';

export async function getDocumentLinks(
workingPath: string | undefined,
Expand Down Expand Up @@ -78,6 +79,14 @@ export async function getDocumentLinks(
}
break;
}
case CompletionType.inputName:
case CompletionType.inputNameWithDeps: {
const link = await namedInputLink(workingPath, node);
if (link) {
links.push(DocumentLink.create(range, link));
}
break;
}
case 'projectTarget': {
const link = await targetLink(workingPath, node);
if (link) {
Expand Down
Loading

0 comments on commit 3656692

Please sign in to comment.