@@ -41,6 +41,9 @@ export class ApplicationTreeProvider implements vscode.TreeDataProvider<Applicat
4141 return Promise . resolve ( [ layout , sources ] ) ;
4242 } else if ( element . type === ApplicationTreeItemType . Layout ) {
4343 const items : ApplicationTreeItem [ ] = [ ] ;
44+ if ( ! element . config ) {
45+ return Promise . resolve ( [ ] ) ;
46+ }
4447 for ( const layout of element . config . layout ) {
4548 items . push ( new ApplicationTreeItem ( layout . name , ApplicationTreeItemType . Template , vscode . TreeItemCollapsibleState . None , element . config , {
4649 command : 'vscode.open' ,
@@ -51,6 +54,9 @@ export class ApplicationTreeProvider implements vscode.TreeDataProvider<Applicat
5154 return Promise . resolve ( items ) ;
5255 } else if ( element . type === ApplicationTreeItemType . Sources ) {
5356 const items : ApplicationTreeItem [ ] = [ ] ;
57+ if ( ! element . config ) {
58+ return Promise . resolve ( [ ] ) ;
59+ }
5460 const sources = await element . config . getSources ( ) ;
5561 for ( const source of sources ) {
5662 items . push ( new ApplicationTreeItem ( source . id , ApplicationTreeItemType . Source , vscode . TreeItemCollapsibleState . Collapsed , element . config , {
@@ -61,6 +67,9 @@ export class ApplicationTreeProvider implements vscode.TreeDataProvider<Applicat
6167 }
6268 return Promise . resolve ( items ) ;
6369 } else if ( element . type === ApplicationTreeItemType . Source ) {
70+ if ( ! element . config ) {
71+ return Promise . resolve ( [ ] ) ;
72+ }
6473 const source = await element . config . getSourceById ( element . label ) ;
6574 if ( ! source ) {
6675 return Promise . resolve ( [ ] ) ;
@@ -81,7 +90,7 @@ export class ApplicationTreeProvider implements vscode.TreeDataProvider<Applicat
8190 const applications = await this . appManager . getApplications ( ) ;
8291 const currentApplication = await this . appManager . getCurrentApplication ( ) ;
8392 const applicationTreeItems = [ ] ;
84- for ( const app of applications ) {
93+ for ( const app of applications ?? [ ] ) {
8594 const itemState = app === currentApplication ? vscode . TreeItemCollapsibleState . Expanded : vscode . TreeItemCollapsibleState . Collapsed ;
8695 applicationTreeItems . push ( new ApplicationTreeItem ( app . name , ApplicationTreeItemType . Application , itemState , undefined ) ) ;
8796 }
@@ -119,7 +128,7 @@ export class ApplicationTreeItem extends vscode.TreeItem {
119128 public readonly label : string ,
120129 public readonly type : ApplicationTreeItemType ,
121130 public readonly collapsibleState : vscode . TreeItemCollapsibleState ,
122- public readonly config : ScgConfig ,
131+ public readonly config : ScgConfig | undefined ,
123132 public readonly command ?: vscode . Command ,
124133 public readonly source ?: string
125134 ) {
@@ -172,26 +181,30 @@ export class JinjaVariablesTreeProvider implements vscode.TreeDataProvider<Jinja
172181 if ( ! element ) {
173182 return Promise . resolve ( this . getJinjaVariables ( ) ) ;
174183 }
184+ return [ ] ;
175185 }
176186
177187 private async getJinjaVariables ( ) : Promise < JinjaVariableNode [ ] > {
178188 const scg = await this . appManager . getCurrentScgContext ( ) ;
179189 if ( ! scg ) {
180- return undefined ;
190+ return [ ] ;
181191 }
182192 const activeEditor = vscode . window . activeTextEditor ;
183193 if ( ! activeEditor ) {
184- return undefined ;
194+ return [ ] ;
185195 }
186196 const filePath = activeEditor . document . uri . fsPath ;
187197 const template = scg . layout . find ( ( t ) => t . name === path . basename ( filePath ) ) ;
188198 if ( ! template || template . source === undefined ) {
189- return undefined ;
199+ return [ ] ;
200+ }
201+ const source = await scg . getSourceById ( template . source ) ;
202+ if ( ! source ) {
203+ return [ ] ;
190204 }
191- const source = await scg . getSourceById ( template . source )
192205 const columns = await source . getHeaders ( ) ;
193206 if ( ! columns ) {
194- return undefined ;
207+ return [ ] ;
195208 }
196209 return columns . map ( column => new JinjaVariableNode ( column , vscode . TreeItemCollapsibleState . None , source ) ) ;
197210 }
@@ -254,7 +267,7 @@ export class SepticFunctionTreeProvider implements vscode.TreeDataProvider<Septi
254267 } else {
255268 label += `${ line . name } = ${ line . alg } ` ;
256269 }
257- const uri = vscode . Uri . parse ( line . uri ) . with ( { fragment : 'L' + ( line . pos . line + 1 ) } ) ;
270+ const uri = vscode . Uri . parse ( line . uri ) . with ( { fragment : 'L' + ( ( line . pos ? .line ?? 0 ) + 1 ) } ) ;
258271 const command : vscode . Command = {
259272 command : 'vscode.open' ,
260273 title : 'Go to function' ,
@@ -265,7 +278,7 @@ export class SepticFunctionTreeProvider implements vscode.TreeDataProvider<Septi
265278 return Promise . resolve ( lines )
266279 } else if ( element . type === SepticFunctionTreeItemType . Inputs ) {
267280 const inputs = element . func . inputs . map ( ( input ) => {
268- const uri = vscode . Uri . parse ( input . uri ) . with ( { fragment : 'L' + ( input . pos . line + 1 ) } ) ;
281+ const uri = vscode . Uri . parse ( input . uri ) . with ( { fragment : 'L' + ( ( input . pos ? .line ?? 0 ) + 1 ) } ) ;
269282 const command : vscode . Command = {
270283 command : 'vscode.open' ,
271284 title : 'Go to function' ,
@@ -275,17 +288,17 @@ export class SepticFunctionTreeProvider implements vscode.TreeDataProvider<Septi
275288 } ) ;
276289 return Promise . resolve ( inputs ) ;
277290 }
278-
291+ return [ ] ;
279292 }
280293
281294 private async getSepticFunctions ( ) : Promise < SepticFunctionTreeItem [ ] > {
282295 const activeEditor = vscode . window . activeTextEditor ;
283296 if ( ! activeEditor ) {
284- return undefined ;
297+ return [ ] ;
285298 }
286299 const functions : SepticFunctionExport [ ] = await this . client . sendRequest ( 'septic/getFunctions' , { uri : activeEditor . document . uri . toString ( ) } ) ;
287300 if ( ! functions || functions . length === 0 ) {
288- return this . functionsCache ? this . functionsCache . map ( func => new SepticFunctionTreeItem ( func . name , vscode . TreeItemCollapsibleState . Collapsed , func , SepticFunctionTreeItemType . Definition ) ) : undefined ;
301+ return this . functionsCache ? this . functionsCache . map ( func => new SepticFunctionTreeItem ( func . name , vscode . TreeItemCollapsibleState . Collapsed , func , SepticFunctionTreeItemType . Definition ) ) : [ ] ;
289302 }
290303 this . functionsCache = functions ;
291304 return functions . map ( func => new SepticFunctionTreeItem ( func . name , vscode . TreeItemCollapsibleState . Collapsed , func , SepticFunctionTreeItemType . Definition ) ) ;
0 commit comments