@@ -18,7 +18,7 @@ const projectJsonPath = join(
1818 workspaceName ,
1919 'apps' ,
2020 workspaceName ,
21- 'project.json'
21+ 'project.json' ,
2222) ;
2323
2424describe ( '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} ) ;
0 commit comments