Skip to content

Commit 3e63a16

Browse files
committed
fix e2e
1 parent 3cc7ff4 commit 3e63a16

File tree

4 files changed

+100
-37
lines changed

4 files changed

+100
-37
lines changed

apps/nxls-e2e/src/document-links/interpolated-path-link.test.ts

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const projectJsonPath = join(
1818
workspaceName,
1919
'apps',
2020
workspaceName,
21-
'project.json'
21+
'project.json',
2222
);
2323

2424
describe('interpolated path links', () => {
@@ -41,8 +41,8 @@ describe('interpolated path links', () => {
4141
interpolatedProject: '{projectRoot}/project.json',
4242
},
4343
null,
44-
2
45-
)
44+
2,
45+
),
4646
);
4747
nxlsWrapper = new NxlsWrapper(true);
4848
await nxlsWrapper.startNxls(join(e2eCwd, workspaceName));
@@ -64,26 +64,62 @@ describe('interpolated path links', () => {
6464
});
6565

6666
it('should return correct links for {workspaceRoot} and {projectRoot}', async () => {
67-
const linkResponse = await nxlsWrapper.sendRequest({
67+
const text = readFileSync(projectJsonPath, 'utf-8');
68+
const lines = text.split('\n');
69+
70+
// Check workspace link
71+
const workspaceLine = lines.findIndex((line) =>
72+
line.includes('{workspaceRoot}/nx.json'),
73+
);
74+
const workspaceChar = lines[workspaceLine].indexOf(
75+
'{workspaceRoot}/nx.json',
76+
);
77+
78+
const workspaceLinkResponse = await nxlsWrapper.sendRequest({
6879
method: 'textDocument/documentLink',
6980
params: {
7081
textDocument: {
7182
uri: URI.file(projectJsonPath).toString(),
7283
},
73-
position: Position.create(0, 1),
84+
position: Position.create(workspaceLine, workspaceChar + 1),
7485
},
7586
});
7687

77-
const links = linkResponse.result as any[];
78-
79-
const workspaceLink = links.find(l => l.target && l.target.endsWith('nx.json'));
80-
const projectLink = links.find(l => l.target && l.target.endsWith('project.json'));
81-
88+
const workspaceLinks = workspaceLinkResponse.result as any[];
89+
const workspaceLink = workspaceLinks.find(
90+
(l) => l.target && l.target.endsWith('nx.json'),
91+
);
8292
expect(workspaceLink).toBeDefined();
83-
expect(decodeURI(workspaceLink.target)).toContain(join(workspaceName, 'nx.json'));
93+
expect(decodeURI(workspaceLink.target)).toContain(
94+
join(workspaceName, 'nx.json'),
95+
);
96+
97+
// Check project link
98+
const projectLine = lines.findIndex((line) =>
99+
line.includes('{projectRoot}/project.json'),
100+
);
101+
const projectChar = lines[projectLine].indexOf(
102+
'{projectRoot}/project.json',
103+
);
84104

105+
const projectLinkResponse = await nxlsWrapper.sendRequest({
106+
method: 'textDocument/documentLink',
107+
params: {
108+
textDocument: {
109+
uri: URI.file(projectJsonPath).toString(),
110+
},
111+
position: Position.create(projectLine, projectChar + 1),
112+
},
113+
});
114+
115+
const projectLinks = projectLinkResponse.result as any[];
116+
const projectLink = projectLinks.find(
117+
(l) => l.target && l.target.endsWith('project.json'),
118+
);
85119
expect(projectLink).toBeDefined();
86-
expect(decodeURI(projectLink.target)).toContain(join(workspaceName, 'apps', workspaceName, 'project.json'));
120+
expect(decodeURI(projectLink.target)).toContain(
121+
join(workspaceName, 'apps', workspaceName, 'project.json'),
122+
);
87123
});
88124

89125
it('should return correct links for negated {workspaceRoot} and {projectRoot}', async () => {
@@ -109,33 +145,62 @@ describe('interpolated path links', () => {
109145
},
110146
});
111147

112-
const linkResponse = await nxlsWrapper.sendRequest({
148+
const text = readFileSync(projectJsonPath, 'utf-8');
149+
writeFileSync('/tmp/debug-project.json', text);
150+
const lines = text.split('\n');
151+
152+
// Check workspace link
153+
const workspaceLine = lines.findIndex((line) =>
154+
line.includes('!{workspaceRoot}/nx.json'),
155+
);
156+
const workspaceChar = lines[workspaceLine].indexOf(
157+
'!{workspaceRoot}/nx.json',
158+
);
159+
160+
const workspaceLinkResponse = await nxlsWrapper.sendRequest({
113161
method: 'textDocument/documentLink',
114162
params: {
115163
textDocument: {
116164
uri: URI.file(projectJsonPath).toString(),
117165
},
118-
position: Position.create(0, 1),
166+
position: Position.create(workspaceLine, workspaceChar + 1),
119167
},
120168
});
121169

122-
const links = linkResponse.result as any[];
123-
124-
const workspaceLink = links.find(
125-
(l) => l.target && l.target.endsWith('nx.json')
126-
);
127-
const projectLink = links.find(
128-
(l) => l.target && l.target.endsWith('project.json')
170+
const workspaceLinks = workspaceLinkResponse.result as any[];
171+
const workspaceLink = workspaceLinks.find(
172+
(l) => l.target && l.target.endsWith('nx.json'),
129173
);
130-
131174
expect(workspaceLink).toBeDefined();
132175
expect(decodeURI(workspaceLink.target)).toContain(
133-
join(workspaceName, 'nx.json')
176+
join(workspaceName, 'nx.json'),
177+
);
178+
179+
// Check project link
180+
const projectLine = lines.findIndex((line) =>
181+
line.includes('!{projectRoot}/project.json'),
134182
);
183+
const projectChar = lines[projectLine].indexOf(
184+
'!{projectRoot}/project.json',
185+
);
186+
187+
const projectLinkResponse = await nxlsWrapper.sendRequest({
188+
method: 'textDocument/documentLink',
189+
params: {
190+
textDocument: {
191+
uri: URI.file(projectJsonPath).toString(),
192+
},
193+
position: Position.create(projectLine, projectChar + 1),
194+
},
195+
});
135196

197+
const projectLinks = projectLinkResponse.result as any[];
198+
const projectLink = projectLinks.find(
199+
(l) => l.target && l.target.endsWith('project.json'),
200+
);
136201
expect(projectLink).toBeDefined();
137202
expect(decodeURI(projectLink.target)).toContain(
138-
join(workspaceName, 'apps', workspaceName, 'project.json')
203+
join(workspaceName, 'apps', workspaceName, 'project.json'),
139204
);
140205
});
141206
});

libs/language-server/capabilities/document-links/src/lib/get-document-links.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ it('should get document links for interpolated paths', async () => {
8686
"interpolatedProject": "{projectRoot}/src/main.ts",
8787
"interpolatedGlob": "{projectRoot}/**/*.ts"
8888
}
89-
`
90-
)
89+
`,
90+
),
9191
);
9292

9393
const matchingSchemas = await languageService.getMatchingSchemas(
@@ -100,14 +100,14 @@ it('should get document links for interpolated paths', async () => {
100100
interpolatedProject: { type: 'string' },
101101
interpolatedGlob: { type: 'string' },
102102
},
103-
}
103+
},
104104
);
105105

106106
const documentLinks = await getDocumentLinks(
107107
'/workspace',
108108
jsonAst,
109109
document,
110-
matchingSchemas
110+
matchingSchemas,
111111
);
112112

113113
expect(documentLinks.map((link) => link.target)).toEqual([
@@ -129,8 +129,8 @@ it('should get document links for negated interpolated paths', async () => {
129129
"interpolatedWorkspace": "!{workspaceRoot}/libs/my-lib/src/index.ts",
130130
"interpolatedProject": "!{projectRoot}/src/main.ts"
131131
}
132-
`
133-
)
132+
`,
133+
),
134134
);
135135

136136
const matchingSchemas = await languageService.getMatchingSchemas(
@@ -142,14 +142,14 @@ it('should get document links for negated interpolated paths', async () => {
142142
interpolatedWorkspace: { type: 'string' },
143143
interpolatedProject: { type: 'string' },
144144
},
145-
}
145+
},
146146
);
147147

148148
const documentLinks = await getDocumentLinks(
149149
'/workspace',
150150
jsonAst,
151151
document,
152-
matchingSchemas
152+
matchingSchemas,
153153
);
154154

155155
expect(documentLinks.map((link) => link.target)).toEqual([
@@ -372,5 +372,4 @@ describe('project links', () => {
372372

373373
documentMapper.dispose();
374374
});
375-
})
376-
375+
});

libs/language-server/capabilities/document-links/src/lib/get-document-links.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
JSONDocument,
1717
MatchingSchema,
1818
TextDocument,
19-
}
20-
from 'vscode-json-languageservice';
19+
} from 'vscode-json-languageservice';
2120
import { createRange } from './create-range';
2221
import { targetLink } from './target-link';
2322
import { namedInputLink } from './named-input-link';

libs/language-server/capabilities/document-links/src/lib/interpolated-path-link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { URI } from 'vscode-uri';
99

1010
export async function interpolatedPathLink(
1111
workingPath: string,
12-
node: ASTNode
12+
node: ASTNode,
1313
): Promise<string | undefined> {
1414
if (!isStringNode(node)) {
1515
return;

0 commit comments

Comments
 (0)