@@ -33,7 +33,10 @@ connection.onInitialize(() => {
3333} ) ;
3434
3535connection . onInitialized ( async ( ) => {
36- await Promise . all ( [ applySettings ( ) , connection . client . register ( DidChangeConfigurationNotification . type ) ] ) ;
36+ await Promise . all ( [
37+ applySettings ( ) ,
38+ connection . client . register ( DidChangeConfigurationNotification . type )
39+ ] ) ;
3740 const _ = compileAndValidate ( ) ;
3841 const workSpaceFolders = await connection . workspace . getWorkspaceFolders ( ) ;
3942 // the first item is the root folder
@@ -43,7 +46,7 @@ connection.onInitialized(async () => {
4346connection . onDidChangeConfiguration ( async ( ) => {
4447 await applySettings ( ) ;
4548 await compileAndValidate ( ) ;
46- } )
49+ } ) ;
4750
4851connection . onRequest ( "compile" , async ( ) => {
4952 const _ = compileAndValidate ( ) ;
@@ -56,15 +59,16 @@ documents.onDidSave(change => {
5659} ) ;
5760
5861async function applySettings ( ) {
59- settings = await connection . workspace . getConfiguration ( ' dataform' ) ;
62+ settings = await connection . workspace . getConfiguration ( " dataform" ) ;
6063}
6164
6265async function compileAndValidate ( ) {
6366 let compilationFailed = false ;
64- const spawnedProcess = spawn (
65- ( process . platform !== "win32" ) ? "dataform" : "dataform.cmd" ,
66- [ "compile" , "--json" , ...settings . compilerOptions ]
67- ) ;
67+ const spawnedProcess = spawn ( process . platform !== "win32" ? "dataform" : "dataform.cmd" , [
68+ "compile" ,
69+ "--json" ,
70+ ...settings . compilerOptions
71+ ] ) ;
6872
6973 const compileResult = await getProcessResult ( spawnedProcess ) ;
7074 if ( compileResult . exitCode !== 0 ) {
@@ -96,14 +100,17 @@ async function compileAndValidate() {
96100
97101 if ( parsedResult ?. graphErrors ?. compilationErrors ) {
98102 parsedResult . graphErrors . compilationErrors . forEach ( compilationError => {
99- connection . sendNotification ( "error" , compilationError . fileName + ": " + compilationError . message ) ;
103+ connection . sendNotification (
104+ "error" ,
105+ compilationError . fileName + ": " + compilationError . message
106+ ) ;
100107 } ) ;
101108 if ( compilationFailed ) {
102- connection . sendNotification (
103- "error" ,
104- "Errors encountered when running 'dataform' CLI. Please check the output for more information."
105- ) ;
106- return ;
109+ connection . sendNotification (
110+ "error" ,
111+ "Errors encountered when running 'dataform' CLI. Please check the output for more information."
112+ ) ;
113+ return ;
107114 }
108115 } else {
109116 connection . sendNotification ( "success" , "Project compiled successfully" ) ;
@@ -158,35 +165,37 @@ connection.onDefinition(
158165 }
159166
160167 // Jump to the one that was clicked or closest
161- const clickedRef = refContents . map (
162- ( refContent ) => ( {
168+ const clickedRef = refContents
169+ . map ( refContent => ( {
163170 refContent,
164171 min : lineWithRef . indexOf ( refContent ) ,
165172 max : lineWithRef . indexOf ( refContent ) + refContent . length - 1
166- } )
167- ) . sort ( ( a , b ) => {
168- // sort in priority of closest to the clicked position
169- // if position is within the refContent, distance is 0
170- let distanceToA = 0 ;
171- if ( params . position . character < a . min ) {
172- distanceToA = a . min - params . position . character ;
173- } else if ( params . position . character > a . max ) {
174- distanceToA = params . position . character - a . max ;
175- }
176-
177- let distanceToB = 0 ;
178- if ( params . position . character < b . min ) {
179- distanceToB = b . min - params . position . character ;
180- } else if ( params . position . character > b . max ) {
181- distanceToB = params . position . character - b . max ;
182- }
183-
184- return distanceToA - distanceToB ;
185- } ) [ 0 ] . refContent ;
173+ } ) )
174+ . sort ( ( a , b ) => {
175+ // sort in priority of closest to the clicked position
176+ // if position is within the refContent, distance is 0
177+ let distanceToA = 0 ;
178+ if ( params . position . character < a . min ) {
179+ distanceToA = a . min - params . position . character ;
180+ } else if ( params . position . character > a . max ) {
181+ distanceToA = params . position . character - a . max ;
182+ }
183+
184+ let distanceToB = 0 ;
185+ if ( params . position . character < b . min ) {
186+ distanceToB = b . min - params . position . character ;
187+ } else if ( params . position . character > b . max ) {
188+ distanceToB = params . position . character - b . max ;
189+ }
190+
191+ return distanceToA - distanceToB ;
192+ } ) [ 0 ] . refContent ;
186193
187194 // split to dataset, schema and name
188- const linkedTable : ITarget = { database : null , schema : null , name : null } ;
189- const splitMatch = clickedRef . match ( / ^ r e f \s * \( \s * ( [ " ' ] ( .+ ?) [ " ' ] ) \s * ( , \s * [ " ' ] ( .+ ?) [ " ' ] \s * ) ? ( , \s * [ " ' ] ( .+ ?) [ " ' ] \s * ) ? , ? \s * \) $ / ) ; // tslint:disable-line
195+ const linkedTable : ITarget = { database : null , schema : null , name : null } ;
196+ const splitMatch = clickedRef . match (
197+ / ^ r e f \s * \( \s * ( [ " ' ] ( .+ ?) [ " ' ] ) \s * ( , \s * [ " ' ] ( .+ ?) [ " ' ] \s * ) ? ( , \s * [ " ' ] ( .+ ?) [ " ' ] \s * ) ? , ? \s * \) $ / // tslint:disable-line
198+ ) ;
190199 if ( splitMatch [ 6 ] !== undefined ) {
191200 linkedTable . database = splitMatch [ 2 ] ;
192201 linkedTable . schema = splitMatch [ 4 ] ;
@@ -200,15 +209,21 @@ connection.onDefinition(
200209 return null ;
201210 }
202211
203- let namePrefix = CACHED_COMPILE_GRAPH . projectConfig ?. tablePrefix
212+ const namePrefix = CACHED_COMPILE_GRAPH . projectConfig ?. tablePrefix ;
204213 let linkedTableNameWtPrefix = "" ;
205- linkedTableNameWtPrefix = ( namePrefix !== undefined ) ? namePrefix + "_" + linkedTable . name : linkedTable . name ;
206-
207- const foundCompileAction = gatherAllActions ( ) . filter ( action => (
208- ( linkedTable . database === null || action ?. target ?. database !== undefined && action . target . database === linkedTable . database )
209- && ( linkedTable . schema === null || action ?. target ?. schema !== undefined && action . target . schema === linkedTable . schema )
210- && action ?. target ?. name !== undefined && ( action . target . name === linkedTable . name || action . target . name === linkedTableNameWtPrefix )
211- ) ) ;
214+ linkedTableNameWtPrefix =
215+ namePrefix !== undefined ? namePrefix + "_" + linkedTable . name : linkedTable . name ;
216+
217+ const foundCompileAction = gatherAllActions ( ) . filter (
218+ action =>
219+ ( linkedTable . database === null ||
220+ ( action ?. target ?. database !== undefined &&
221+ action . target . database === linkedTable . database ) ) &&
222+ ( linkedTable . schema === null ||
223+ ( action ?. target ?. schema !== undefined && action . target . schema === linkedTable . schema ) ) &&
224+ action ?. target ?. name !== undefined &&
225+ ( action . target . name === linkedTable . name || action . target . name === linkedTableNameWtPrefix )
226+ ) ;
212227 if ( foundCompileAction . length === 0 ) {
213228 connection . sendNotification ( "error" , `Definition not found for ${ clickedRef } ` ) ;
214229 return null ;
0 commit comments