@@ -3,13 +3,14 @@ import globby from "globby";
33import os from "os" ;
44import path from "path" ;
55import util from "util" ;
6- import { IConnection } from "vscode-languageserver" ;
6+ import { IConnection , ProgressType } from "vscode-languageserver" ;
77import { URI } from "vscode-uri" ;
88import Parser , { Tree } from "web-tree-sitter" ;
99import { 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" ;
1314
1415const readFile = util . promisify ( fs . readFile ) ;
1516const readdir = util . promisify ( fs . readdir ) ;
@@ -42,8 +43,8 @@ export class ElmWorkspace {
4243 this . imports = new Imports ( parser ) ;
4344 }
4445
45- public async init ( ) {
46- await this . initWorkspace ( ) ;
46+ public async init ( progress : WorkDoneProgress ) {
47+ await this . initWorkspace ( progress ) ;
4748 }
4849
4950 public hasDocument ( uri : URI ) : boolean {
@@ -68,7 +69,9 @@ export class ElmWorkspace {
6869 return this . rootPath ;
6970 }
7071
71- private async initWorkspace ( ) {
72+ private async initWorkspace ( x : WorkDoneProgress ) {
73+ let progress = 0 ;
74+ x . begin ( "Indexing" , progress ) ;
7275 let elmVersion ;
7376 try {
7477 elmVersion = await utils . getElmVersion (
@@ -183,18 +186,24 @@ export class ElmWorkspace {
183186 }
184187
185188 const promiseList : Promise < void > [ ] = [ ] ;
189+ const progressSteps = ( elmFilePaths . length * 2 ) / 100 ;
186190 for ( const filePath of elmFilePaths ) {
191+ progress += progressSteps ;
192+ x . report ( progressSteps ) ;
187193 promiseList . push ( this . readAndAddToForest ( filePath ) ) ;
188194 }
189195 await Promise . all ( promiseList ) ;
190196
191197 this . forest . treeIndex . forEach ( item => {
198+ progress += progressSteps ;
199+ x . report ( progressSteps ) ;
192200 this . connection . console . info (
193201 `Adding imports ${ URI . parse ( item . uri ) . fsPath } ` ,
194202 ) ;
195203 this . imports . updateImports ( item . uri , item . tree , this . forest ) ;
196204 } ) ;
197205
206+ x . done ( ) ;
198207 this . connection . console . info ( "Done parsing all files." ) ;
199208 } catch ( error ) {
200209 this . connection . console . error ( error . stack ) ;
0 commit comments