-
Notifications
You must be signed in to change notification settings - Fork 692
Expand file tree
/
Copy pathsettingUtils.ts
More file actions
192 lines (176 loc) · 4.72 KB
/
settingUtils.ts
File metadata and controls
192 lines (176 loc) · 4.72 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
import { workspace, WorkspaceConfiguration } from "vscode";
import { DescriptionConfiguration } from "../shared";
export function getWorkspaceConfiguration(): WorkspaceConfiguration {
return workspace.getConfiguration("leetcode");
}
export function shouldHideSolvedProblem(): boolean {
return getWorkspaceConfiguration().get<boolean>("hideSolved", false);
}
export function getWorkspaceFolder(): string {
return getWorkspaceConfiguration().get<string>("workspaceFolder", "");
}
export function getEditorShortcuts(): string[] {
return getWorkspaceConfiguration().get<string[]>("editor.shortcuts", ["submit", "test"]);
}
export function hasStarShortcut(): boolean {
const shortcuts: string[] = getWorkspaceConfiguration().get<string[]>("editor.shortcuts", ["submit", "test"]);
return shortcuts.indexOf("star") >= 0;
}
export function shouldUseEndpointTranslation(): boolean {
return getWorkspaceConfiguration().get<boolean>("useEndpointTranslation", true);
}
export function getDescriptionConfiguration(): IDescriptionConfiguration {
const setting: string = getWorkspaceConfiguration().get<string>("showDescription", DescriptionConfiguration.InWebView);
const config: IDescriptionConfiguration = {
showInComment: false,
showInWebview: true,
};
switch (setting) {
case DescriptionConfiguration.Both:
config.showInComment = true;
config.showInWebview = true;
break;
case DescriptionConfiguration.None:
config.showInComment = false;
config.showInWebview = false;
break;
case DescriptionConfiguration.InFileComment:
config.showInComment = true;
config.showInWebview = false;
break;
case DescriptionConfiguration.InWebView:
config.showInComment = false;
config.showInWebview = true;
break;
}
// To be compatible with the deprecated setting:
if (getWorkspaceConfiguration().get<boolean>("showCommentDescription")) {
config.showInComment = true;
}
return config;
}
const defaultPreambles = {
"cpp": `
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
`
}
/**
* ## About
*
* Code preamble is a short code snippet adding to the beginning of the program. A typical one is:
*
*
* ```
* #include <iostream>
* using namespace std;
* ```
*
* This feature is useful. Maybe inserting header files is interesting for the first several times,
* it is dreadful if we need to add tons of it each time we do the problems, especially for a dreadful
* language like C/C++
*
* ## Configuration
*
* To add a preamble for one language, the user will follow this schema:
*
* ```
* "leetcode.language.preamble" = {
* "cpp" : "#include <iostream>",
* }
* ```
*
* @param language
*/
export function getCodePreamble(language: string): string {
const preambles = getWorkspaceConfiguration().get<Record<string, string>>("language.preamble");
return preambles?.[language] ?? defaultPreambles?.[language] ?? "";
}
export interface IDescriptionConfiguration {
showInComment: boolean;
showInWebview: boolean;
}