44 */
55
66import fs from '../fs/fs'
7+ import * as vscode from 'vscode'
78import { ToolkitError } from '../errors'
89import * as semver from 'semver'
910import * as path from 'path'
@@ -22,6 +23,20 @@ export class LanguageServerResolver {
2223 private readonly _defaultDownloadFolder ?: string
2324 ) { }
2425
26+ // wraps the resolver to show download status message
27+ async resolveWithProgress ( ) {
28+ return vscode . window . withProgress (
29+ {
30+ location : vscode . ProgressLocation . Notification ,
31+ title : `Downloading '${ this . lsName } ' language server` ,
32+ cancellable : false ,
33+ } ,
34+ async ( progress ) => {
35+ return this . resolve ( )
36+ }
37+ )
38+ }
39+
2540 /**
2641 * Downloads and sets up the Language Server, attempting different locations in order:
2742 * 1. Local cache
@@ -30,63 +45,67 @@ export class LanguageServerResolver {
3045 * @throws ToolkitError if no compatible version can be found
3146 */
3247 async resolve ( ) {
33- const result : LspResult = {
34- location : 'unknown' ,
35- version : '' ,
36- assetDirectory : '' ,
37- }
38-
39- const latestVersion = this . latestCompatibleLspVersion ( )
40- const targetContents = this . getLSPTargetContents ( latestVersion )
41- const cacheDirectory = this . getDownloadDirectory ( latestVersion . serverVersion )
48+ try {
49+ const result : LspResult = {
50+ location : 'unknown' ,
51+ version : '' ,
52+ assetDirectory : '' ,
53+ }
4254
43- if ( await this . hasValidLocalCache ( cacheDirectory , targetContents ) ) {
44- result . location = 'cache'
45- result . version = latestVersion . serverVersion
46- result . assetDirectory = cacheDirectory
47- return result
48- } else {
49- // Delete the cached directory since it's invalid
50- if ( await fs . existsDir ( cacheDirectory ) ) {
51- await fs . delete ( cacheDirectory , {
52- recursive : true ,
53- } )
55+ const latestVersion = this . latestCompatibleLspVersion ( )
56+ const targetContents = this . getLSPTargetContents ( latestVersion )
57+ const cacheDirectory = this . getDownloadDirectory ( latestVersion . serverVersion )
58+
59+ if ( await this . hasValidLocalCache ( cacheDirectory , targetContents ) ) {
60+ result . location = 'cache'
61+ result . version = latestVersion . serverVersion
62+ result . assetDirectory = cacheDirectory
63+ return result
64+ } else {
65+ // Delete the cached directory since it's invalid
66+ if ( await fs . existsDir ( cacheDirectory ) ) {
67+ await fs . delete ( cacheDirectory , {
68+ recursive : true ,
69+ } )
70+ }
5471 }
55- }
5672
57- if ( await this . downloadRemoteTargetContent ( targetContents , latestVersion . serverVersion ) ) {
58- result . location = 'remote'
59- result . version = latestVersion . serverVersion
60- result . assetDirectory = cacheDirectory
61- return result
62- } else {
63- // clean up any leftover content that may have been downloaded
64- if ( await fs . existsDir ( cacheDirectory ) ) {
65- await fs . delete ( cacheDirectory , {
66- recursive : true ,
67- } )
73+ if ( await this . downloadRemoteTargetContent ( targetContents , latestVersion . serverVersion ) ) {
74+ result . location = 'remote'
75+ result . version = latestVersion . serverVersion
76+ result . assetDirectory = cacheDirectory
77+ return result
78+ } else {
79+ // clean up any leftover content that may have been downloaded
80+ if ( await fs . existsDir ( cacheDirectory ) ) {
81+ await fs . delete ( cacheDirectory , {
82+ recursive : true ,
83+ } )
84+ }
6885 }
69- }
7086
71- logger . info (
72- `Unable to download language server version ${ latestVersion . serverVersion } . Attempting to fetch from fallback location`
73- )
87+ logger . info (
88+ `Unable to download language server version ${ latestVersion . serverVersion } . Attempting to fetch from fallback location`
89+ )
7490
75- const fallbackDirectory = await this . getFallbackDir ( latestVersion . serverVersion )
76- if ( ! fallbackDirectory ) {
77- throw new ToolkitError ( 'Unable to find a compatible version of the Language Server' )
78- }
91+ const fallbackDirectory = await this . getFallbackDir ( latestVersion . serverVersion )
92+ if ( ! fallbackDirectory ) {
93+ throw new ToolkitError ( 'Unable to find a compatible version of the Language Server' )
94+ }
7995
80- const version = path . basename ( fallbackDirectory )
81- logger . info (
82- `Unable to install ${ this . lsName } language server v${ latestVersion . serverVersion } . Launching a previous version from ${ fallbackDirectory } `
83- )
96+ const version = path . basename ( fallbackDirectory )
97+ logger . info (
98+ `Unable to install ${ this . lsName } language server v${ latestVersion . serverVersion } . Launching a previous version from ${ fallbackDirectory } `
99+ )
84100
85- result . location = 'fallback'
86- result . version = version
87- result . assetDirectory = fallbackDirectory
101+ result . location = 'fallback'
102+ result . version = version
103+ result . assetDirectory = fallbackDirectory
88104
89- return result
105+ return result
106+ } finally {
107+ logger . info ( `Finished setting up LSP server` )
108+ }
90109 }
91110
92111 /**
0 commit comments