@@ -10,11 +10,10 @@ import { WorkspaceProgress } from '../extension';
10
10
import { download , fetchRelease } from '../net' ;
11
11
import * as rustup from '../rustup' ;
12
12
import { Observable } from '../utils/observable' ;
13
+ import { Metadata , readMetadata , writeMetadata } from './persistent_state' ;
13
14
14
15
const stat = promisify ( fs . stat ) ;
15
16
const mkdir = promisify ( fs . mkdir ) ;
16
- const readFile = promisify ( fs . readFile ) ;
17
- const writeFile = promisify ( fs . writeFile ) ;
18
17
19
18
const REQUIRED_COMPONENTS = [ 'rust-src' ] ;
20
19
@@ -45,27 +44,6 @@ function installDir(): string | undefined {
45
44
return undefined ;
46
45
}
47
46
48
- /** Returns a path where persistent data for rust-analyzer should be installed. */
49
- function metadataDir ( ) : string | undefined {
50
- if ( process . platform === 'linux' || process . platform === 'darwin' ) {
51
- // Prefer, in this order:
52
- // 1. $XDG_CONFIG_HOME/rust-analyzer
53
- // 2. $HOME/.config/rust-analyzer
54
- const { HOME , XDG_CONFIG_HOME } = process . env ;
55
- const baseDir = XDG_CONFIG_HOME || ( HOME && path . join ( HOME , '.config' ) ) ;
56
-
57
- return baseDir && path . resolve ( path . join ( baseDir , 'rust-analyzer' ) ) ;
58
- } else if ( process . platform === 'win32' ) {
59
- // %LocalAppData%\rust-analyzer\
60
- const { LocalAppData } = process . env ;
61
- return (
62
- LocalAppData && path . resolve ( path . join ( LocalAppData , 'rust-analyzer' ) )
63
- ) ;
64
- }
65
-
66
- return undefined ;
67
- }
68
-
69
47
function ensureDir ( path : string ) {
70
48
return ! ! path && stat ( path ) . catch ( ( ) => mkdir ( path , { recursive : true } ) ) ;
71
49
}
@@ -77,40 +55,6 @@ interface RustAnalyzerConfig {
77
55
} ;
78
56
}
79
57
80
- interface Metadata {
81
- releaseTag : string ;
82
- }
83
-
84
- async function readMetadata ( ) : Promise < Metadata | Record < string , unknown > > {
85
- const stateDir = metadataDir ( ) ;
86
- if ( ! stateDir ) {
87
- return { kind : 'error' , code : 'NotSupported' } ;
88
- }
89
-
90
- const filePath = path . join ( stateDir , 'metadata.json' ) ;
91
- if ( ! ( await stat ( filePath ) . catch ( ( ) => false ) ) ) {
92
- return { kind : 'error' , code : 'FileMissing' } ;
93
- }
94
-
95
- const contents = await readFile ( filePath , 'utf8' ) ;
96
- const obj = JSON . parse ( contents ) as unknown ;
97
- return typeof obj === 'object' ? ( obj as Record < string , unknown > ) : { } ;
98
- }
99
-
100
- async function writeMetadata ( config : Metadata ) {
101
- const stateDir = metadataDir ( ) ;
102
- if ( ! stateDir ) {
103
- return false ;
104
- }
105
-
106
- if ( ! ( await ensureDir ( stateDir ) ) ) {
107
- return false ;
108
- }
109
-
110
- const filePath = path . join ( stateDir , 'metadata.json' ) ;
111
- return writeFile ( filePath , JSON . stringify ( config ) ) . then ( ( ) => true ) ;
112
- }
113
-
114
58
export async function getServer ( {
115
59
askBeforeDownload,
116
60
package : pkg ,
0 commit comments