@@ -10,7 +10,6 @@ import { Forest } from "./forest";
1010import { Imports } from "./imports" ;
1111import * as utils from "./util/elmUtils" ;
1212import { Settings } from "./util/settings" ;
13- import { WorkDoneProgress } from "vscode-languageserver/lib/progress" ;
1413
1514const readFile = util . promisify ( fs . readFile ) ;
1615const readdir = util . promisify ( fs . readdir ) ;
@@ -43,8 +42,8 @@ export class ElmWorkspace {
4342 this . imports = new Imports ( parser ) ;
4443 }
4544
46- public async init ( progress : WorkDoneProgress ) {
47- await this . initWorkspace ( progress ) ;
45+ public async init ( progressCallback : ( percent : number ) => void ) {
46+ await this . initWorkspace ( progressCallback ) ;
4847 }
4948
5049 public hasDocument ( uri : URI ) : boolean {
@@ -69,9 +68,8 @@ export class ElmWorkspace {
6968 return this . rootPath ;
7069 }
7170
72- private async initWorkspace ( x : WorkDoneProgress ) {
71+ private async initWorkspace ( progressCallback : ( percent : number ) => void ) {
7372 let progress = 0 ;
74- x . begin ( "Indexing" , progress ) ;
7573 let elmVersion ;
7674 try {
7775 elmVersion = await utils . getElmVersion (
@@ -84,9 +82,9 @@ export class ElmWorkspace {
8482 `Could not figure out elm version, this will impact how good the server works. \n ${ e . stack } ` ,
8583 ) ;
8684 }
85+ const pathToElmJson = path . join ( this . rootPath . fsPath , "elm.json" ) ;
86+ this . connection . console . info ( `Reading elm.json from ${ pathToElmJson } ` ) ;
8787 try {
88- const pathToElmJson = path . join ( this . rootPath . fsPath , "elm.json" ) ;
89- this . connection . console . info ( `Reading elm.json from ${ pathToElmJson } ` ) ;
9088 // Find elm files and feed them to tree sitter
9189 const elmJson = require ( pathToElmJson ) ;
9290 const type = elmJson . type ;
@@ -186,27 +184,33 @@ export class ElmWorkspace {
186184 }
187185
188186 const promiseList : Promise < void > [ ] = [ ] ;
189- const progressSteps = ( elmFilePaths . length * 2 ) / 100 ;
187+ const PARSE_STAGES = 3 ;
188+ const progressDelta = 100 / ( elmFilePaths . length * PARSE_STAGES ) ;
190189 for ( const filePath of elmFilePaths ) {
191- progress += progressSteps ;
192- x . report ( progressSteps ) ;
193- promiseList . push ( this . readAndAddToForest ( filePath ) ) ;
190+ progressCallback ( ( progress += progressDelta ) ) ;
191+ promiseList . push (
192+ this . readAndAddToForest ( filePath , ( ) => {
193+ progressCallback ( ( progress += progressDelta ) ) ;
194+ } ) ,
195+ ) ;
194196 }
195197 await Promise . all ( promiseList ) ;
196198
197199 this . forest . treeIndex . forEach ( item => {
198- progress += progressSteps ;
199- x . report ( progressSteps ) ;
200200 this . connection . console . info (
201201 `Adding imports ${ URI . parse ( item . uri ) . fsPath } ` ,
202202 ) ;
203203 this . imports . updateImports ( item . uri , item . tree , this . forest ) ;
204+ progressCallback ( ( progress += progressDelta ) ) ;
204205 } ) ;
205206
206- x . done ( ) ;
207- this . connection . console . info ( "Done parsing all files." ) ;
207+ this . connection . console . info (
208+ `Done parsing all files for ${ pathToElmJson } ` ,
209+ ) ;
208210 } catch ( error ) {
209- this . connection . console . error ( error . stack ) ;
211+ this . connection . console . error (
212+ `Error parsing files for ${ pathToElmJson } :\n${ error . stack } ` ,
213+ ) ;
210214 }
211215 }
212216
@@ -257,7 +261,10 @@ export class ElmWorkspace {
257261 : `${ os . homedir ( ) } /.elm` ;
258262 }
259263
260- private async readAndAddToForest ( filePath : IFolder ) : Promise < void > {
264+ private async readAndAddToForest (
265+ filePath : IFolder ,
266+ callback : ( ) => void ,
267+ ) : Promise < void > {
261268 return new Promise ( async ( resolve , reject ) => {
262269 try {
263270 this . connection . console . info ( `Adding ${ filePath . path . toString ( ) } ` ) ;
@@ -273,6 +280,7 @@ export class ElmWorkspace {
273280 tree ,
274281 filePath . maintainerAndPackageName ,
275282 ) ;
283+ callback ( ) ;
276284 resolve ( ) ;
277285 } catch ( error ) {
278286 this . connection . console . error ( error . stack ) ;
0 commit comments