This repository was archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfigurationCache.ts
81 lines (67 loc) · 2.1 KB
/
configurationCache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let currentFingerprint: string | undefined;
let codigaApiToken: any = undefined;
/**
* Since there are client applications that don't support multiple workspaces, but only a single one
* (announced via 'InitializeParams.rootUri'), we have to rely on string URI values instead of `WorkspaceFolder` objects.
*/
let workspaceFolderUris: string[] = [];
// -------- Fingerprint --------
/**
* Caches the user fingerprint regardless if it is generated on the client or on server side.
*
* @param fingerprint
*/
export function cacheUserFingerprint(fingerprint: string | undefined) {
currentFingerprint = fingerprint;
}
const generateRandomString = (length: number) => {
// Declare all characters
const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let str = "";
for (let i = 0; i < length; i++) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
}
return str;
};
/**
* Get the user fingerprint from the configuration.
*
* Currently, if the fingerprint is generated on server side, it is re-generated for each launch of the language server.
*/
export function getUserFingerprint(): string {
if (currentFingerprint) {
return currentFingerprint;
}
const newFingerprint = generateRandomString(10);
currentFingerprint = newFingerprint;
return newFingerprint;
}
// -------- Codiga API Token --------
/**
* Get the Codiga API Token from the client application preferences.
*/
export function getApiToken(): any {
return codigaApiToken;
}
/**
* Caches the api token on server side to minimize the server to client calls.
*/
export function cacheCodigaApiToken(apiToken: any) {
codigaApiToken = apiToken;
}
// -------- Workspace folders --------
/**
* Saves the argument workspace folders. If null is provided, then an empty list is cached.
*
* @param folderUris the workspace folder URIs to cache
*/
export function cacheWorkspaceFolders(folderUris: string[] | null) {
workspaceFolderUris = folderUris ?? [];
}
/**
* Returns the workspace folders from this cache.
*/
export function getWorkspaceFolders(): string[] {
return workspaceFolderUris;
}