• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ES2PANDA_LSP_USER_PREFERENCES_H
17 #define ES2PANDA_LSP_USER_PREFERENCES_H
18 
19 #include <string>
20 
21 namespace ark::es2panda::lsp {
22 class UserPreferences {
23 public:
24     /**
25      *  @brief Quote preference options
26      *
27      * AUTO   - Let the editor decide based on context
28      * DOUBLE - Always use double quotes (")
29      * SINGLE - Always use single quotes (')
30      */
31     enum class QuotePreference { AUTO, DOUBLE, SINGLE };
32 
33     /**
34      * @brief Controls the automatic imports
35      *
36      * AUTO - Automatically determine whether to include imports based on project context
37      * ON   - Always include automatic imports
38      * OFF  - Never include automatic imports
39      */
40     enum class IncludePackageJsonAutoImports { AUTO, ON, OFF };
41 
42     /**
43      * @brief Controls the display of parameter name hints in function calls
44      *
45      * NONE      - No parameter name hints shown
46      * LITERALS  - Show parameter hints only for literal arguments
47      * ALL       - Show parameter hints for all arguments
48      */
49     enum class IncludeInlayParameterNameHints { NONE, LITERALS, ALL };
50 
51     /**
52      * @brief Determines how module import paths are specified
53      *
54      * SHORTEST          - Use the shortest possible path
55      * PROJECT_RELATIVE  - Use paths relative to the project root
56      * RELATIVE          - Use paths relative to the current file
57      * NON_RELATIVE      - Use absolute paths
58      */
59     enum class ImportModuleSpecifierPreference { SHORTEST, PROJECT_RELATIVE, RELATIVE, NON_RELATIVE };
60 
61     /**
62      * @brief Controls the file extension style in import statements
63      *
64      * AUTO     - Automatically determine the appropriate ending
65      * MINIMAL  - Omit extension when possible
66      * INDEX    - Include '/index' in paths
67      * JS       - Include '.js' extension
68      */
69     enum class ImportModuleSpecifierEnding { AUTO, MINIMAL, INDEX, JS };
70 
71 private:
72     QuotePreference quotePreference_ = QuotePreference::AUTO;
73     IncludePackageJsonAutoImports includePackageJsonAutoImports_ = IncludePackageJsonAutoImports::AUTO;
74     IncludeInlayParameterNameHints includeInlayParameterNameHints_ = IncludeInlayParameterNameHints::NONE;
75     ImportModuleSpecifierPreference importModuleSpecifierPreference_ = ImportModuleSpecifierPreference::SHORTEST;
76     ImportModuleSpecifierEnding importModuleSpecifierEnding_ = ImportModuleSpecifierEnding::AUTO;
77     std::string autoImportFileExcludePatterns_;
78     bool disableSuggestions_ = false;
79     bool includeCompletionsForModuleExports_ = false;
80     bool includeCompletionsForImportStatements_ = false;
81     bool includeCompletionsWithSnippetText_ = false;
82     bool includeCompletionsChainCompletions_ = false;
83     bool includeCompletionsWithInsertText_ = false;
84     bool includeCompletionsClassMemberSnippets_ = false;
85     bool includeCompletionsWithObjectLiteralMethodSnippets_ = false;
86     bool useLabelDetailsIncompletionsEntries_ = false;
87     bool allowIncompleteCompletions_ = false;
88     bool allowTextChangesInNewFiles_ = false;
89     bool providePrefixAndSuffixTextForRename_ = false;
90     bool provideRefactorNotApplicableReason_ = false;
91     bool includeInlayParameterNameHintsWhenArgumentMatchesName_ = false;
92     bool includeInlayFunctionParameterTypeHints_ = false;
93     bool includeInlayVariableTypeHints_ = false;
94     bool includeInlayVariableTypeHintsWhenTypeMatchesName_ = false;
95     bool includeInlayPropertyDeclarationTypeHints_ = false;
96     bool includeInlayFunctionLikeReturnTypeHints_ = false;
97     bool includeInlayEnumMemberValueHints_ = false;
98     bool allowRenameOfImportPath_ = false;
99 
100 public:
101     /*default preferences*/
GetDefaultUserPreferences()102     static UserPreferences GetDefaultUserPreferences()
103     {
104         return UserPreferences();
105     }
106 
107     /*current preferences*/
GetUserPreferences()108     UserPreferences *GetUserPreferences()
109     {
110         return this;
111     }
112 
113     // Setters for enum types
SetQuotePreference(QuotePreference value)114     void SetQuotePreference(QuotePreference value)
115     {
116         quotePreference_ = value;
117     }
118 
SetIncludePackageJsonAutoImports(IncludePackageJsonAutoImports value)119     void SetIncludePackageJsonAutoImports(IncludePackageJsonAutoImports value)
120     {
121         includePackageJsonAutoImports_ = value;
122     }
123 
SetIncludeInlayParameterNameHints(IncludeInlayParameterNameHints value)124     void SetIncludeInlayParameterNameHints(IncludeInlayParameterNameHints value)
125     {
126         includeInlayParameterNameHints_ = value;
127     }
128 
SetImportModuleSpecifierPreference(ImportModuleSpecifierPreference value)129     void SetImportModuleSpecifierPreference(ImportModuleSpecifierPreference value)
130     {
131         importModuleSpecifierPreference_ = value;
132     }
133 
SetImportModuleSpecifierEnding(ImportModuleSpecifierEnding value)134     void SetImportModuleSpecifierEnding(ImportModuleSpecifierEnding value)
135     {
136         importModuleSpecifierEnding_ = value;
137     }
138 
SetAutoImportFileExcludePatterns(const std::string & patterns)139     void SetAutoImportFileExcludePatterns(const std::string &patterns)
140     {
141         autoImportFileExcludePatterns_ = patterns;
142     }
143 
144     // Setters for boolean values
SetDisableSuggestions(bool value)145     void SetDisableSuggestions(bool value)
146     {
147         disableSuggestions_ = value;
148     }
149 
SetIncludeCompletionsForModuleExports(bool value)150     void SetIncludeCompletionsForModuleExports(bool value)
151     {
152         includeCompletionsForModuleExports_ = value;
153     }
154 
SetIncludeCompletionsForImportStatements(bool value)155     void SetIncludeCompletionsForImportStatements(bool value)
156     {
157         includeCompletionsForImportStatements_ = value;
158     }
159 
SetIncludeCompletionsWithSnippetText(bool value)160     void SetIncludeCompletionsWithSnippetText(bool value)
161     {
162         includeCompletionsWithSnippetText_ = value;
163     }
164 
SetIncludeCompletionsChainCompletions(bool value)165     void SetIncludeCompletionsChainCompletions(bool value)
166     {
167         includeCompletionsChainCompletions_ = value;
168     }
169 
SetIncludeCompletionsWithInsertText(bool value)170     void SetIncludeCompletionsWithInsertText(bool value)
171     {
172         includeCompletionsWithInsertText_ = value;
173     }
174 
SetIncludeCompletionsClassMemberSnippets(bool value)175     void SetIncludeCompletionsClassMemberSnippets(bool value)
176     {
177         includeCompletionsClassMemberSnippets_ = value;
178     }
179 
SetIncludeCompletionsWithObjectLiteralMethodSnippets(bool value)180     void SetIncludeCompletionsWithObjectLiteralMethodSnippets(bool value)
181     {
182         includeCompletionsWithObjectLiteralMethodSnippets_ = value;
183     }
184 
SetUseLabelDetailsIncompletionsEntries(bool value)185     void SetUseLabelDetailsIncompletionsEntries(bool value)
186     {
187         useLabelDetailsIncompletionsEntries_ = value;
188     }
189 
SetAllowIncompleteCompletions(bool value)190     void SetAllowIncompleteCompletions(bool value)
191     {
192         allowIncompleteCompletions_ = value;
193     }
194 
SetAllowTextChangesInNewFiles(bool value)195     void SetAllowTextChangesInNewFiles(bool value)
196     {
197         allowTextChangesInNewFiles_ = value;
198     }
199 
SetProvidePrefixAndSuffixTextForRename(bool value)200     void SetProvidePrefixAndSuffixTextForRename(bool value)
201     {
202         providePrefixAndSuffixTextForRename_ = value;
203     }
204 
SetProvideRefactorNotApplicableReason(bool value)205     void SetProvideRefactorNotApplicableReason(bool value)
206     {
207         provideRefactorNotApplicableReason_ = value;
208     }
209 
SetIncludeInlayParameterNameHintsWhenArgumentMatchesName(bool value)210     void SetIncludeInlayParameterNameHintsWhenArgumentMatchesName(bool value)
211     {
212         includeInlayParameterNameHintsWhenArgumentMatchesName_ = value;
213     }
214 
SetIncludeInlayFunctionParameterTypeHints(bool value)215     void SetIncludeInlayFunctionParameterTypeHints(bool value)
216     {
217         includeInlayFunctionParameterTypeHints_ = value;
218     }
219 
SetIncludeInlayVariableTypeHints(bool value)220     void SetIncludeInlayVariableTypeHints(bool value)
221     {
222         includeInlayVariableTypeHints_ = value;
223     }
224 
SetIncludeInlayVariableTypeHintsWhenTypeMatchesName(bool value)225     void SetIncludeInlayVariableTypeHintsWhenTypeMatchesName(bool value)
226     {
227         includeInlayVariableTypeHintsWhenTypeMatchesName_ = value;
228     }
229 
SetIncludeInlayPropertyDeclarationTypeHints(bool value)230     void SetIncludeInlayPropertyDeclarationTypeHints(bool value)
231     {
232         includeInlayPropertyDeclarationTypeHints_ = value;
233     }
234 
SetIncludeInlayFunctionLikeReturnTypeHints(bool value)235     void SetIncludeInlayFunctionLikeReturnTypeHints(bool value)
236     {
237         includeInlayFunctionLikeReturnTypeHints_ = value;
238     }
239 
SetIncludeInlayEnumMemberValueHints(bool value)240     void SetIncludeInlayEnumMemberValueHints(bool value)
241     {
242         includeInlayEnumMemberValueHints_ = value;
243     }
244 
SetAllowRenameOfImportPath(bool value)245     void SetAllowRenameOfImportPath(bool value)
246     {
247         allowRenameOfImportPath_ = value;
248     }
249 
GetQuotePreference()250     QuotePreference GetQuotePreference() const
251     {
252         return quotePreference_;
253     }
254 
GetIncludePackageJsonAutoImports()255     IncludePackageJsonAutoImports GetIncludePackageJsonAutoImports() const
256     {
257         return includePackageJsonAutoImports_;
258     }
259 
GetIncludeInlayParameterNameHints()260     IncludeInlayParameterNameHints GetIncludeInlayParameterNameHints() const
261     {
262         return includeInlayParameterNameHints_;
263     }
264 
GetImportModuleSpecifierPreference()265     ImportModuleSpecifierPreference GetImportModuleSpecifierPreference() const
266     {
267         return importModuleSpecifierPreference_;
268     }
269 
GetImportModuleSpecifierEnding()270     ImportModuleSpecifierEnding GetImportModuleSpecifierEnding() const
271     {
272         return importModuleSpecifierEnding_;
273     }
274 
GetAutoImportFileExcludePatterns()275     std::string GetAutoImportFileExcludePatterns() const
276     {
277         return autoImportFileExcludePatterns_;
278     }
279 
GetDisableSuggestions()280     bool GetDisableSuggestions() const
281     {
282         return disableSuggestions_;
283     }
284 
GetIncludeCompletionsForModuleExports()285     bool GetIncludeCompletionsForModuleExports() const
286     {
287         return includeCompletionsForModuleExports_;
288     }
289 
GetIncludeCompletionsForImportStatements()290     bool GetIncludeCompletionsForImportStatements() const
291     {
292         return includeCompletionsForImportStatements_;
293     }
294 
GetIncludeCompletionsWithSnippetText()295     bool GetIncludeCompletionsWithSnippetText() const
296     {
297         return includeCompletionsWithSnippetText_;
298     }
299 
GetIncludeCompletionsChainCompletions()300     bool GetIncludeCompletionsChainCompletions() const
301     {
302         return includeCompletionsChainCompletions_;
303     }
304 
GetIncludeCompletionsWithInsertText()305     bool GetIncludeCompletionsWithInsertText() const
306     {
307         return includeCompletionsWithInsertText_;
308     }
309 
GetIncludeCompletionsClassMemberSnippets()310     bool GetIncludeCompletionsClassMemberSnippets() const
311     {
312         return includeCompletionsClassMemberSnippets_;
313     }
314 
GetIncludeCompletionsWithObjectLiteralMethodSnippets()315     bool GetIncludeCompletionsWithObjectLiteralMethodSnippets() const
316     {
317         return includeCompletionsWithObjectLiteralMethodSnippets_;
318     }
319 
GetUseLabelDetailsIncompletionsEntries()320     bool GetUseLabelDetailsIncompletionsEntries() const
321     {
322         return useLabelDetailsIncompletionsEntries_;
323     }
324 
GetAllowIncompleteCompletions()325     bool GetAllowIncompleteCompletions() const
326     {
327         return allowIncompleteCompletions_;
328     }
329 
GetAllowTextChangesInNewFiles()330     bool GetAllowTextChangesInNewFiles() const
331     {
332         return allowTextChangesInNewFiles_;
333     }
334 
GetProvidePrefixAndSuffixTextForRename()335     bool GetProvidePrefixAndSuffixTextForRename() const
336     {
337         return providePrefixAndSuffixTextForRename_;
338     }
339 
GetProvideRefactorNotApplicableReason()340     bool GetProvideRefactorNotApplicableReason() const
341     {
342         return provideRefactorNotApplicableReason_;
343     }
344 
GetIncludeInlayParameterNameHintsWhenArgumentMatchesName()345     bool GetIncludeInlayParameterNameHintsWhenArgumentMatchesName() const
346     {
347         return includeInlayParameterNameHintsWhenArgumentMatchesName_;
348     }
349 
GetIncludeInlayFunctionParameterTypeHints()350     bool GetIncludeInlayFunctionParameterTypeHints() const
351     {
352         return includeInlayFunctionParameterTypeHints_;
353     }
354 
GetIncludeInlayVariableTypeHints()355     bool GetIncludeInlayVariableTypeHints() const
356     {
357         return includeInlayVariableTypeHints_;
358     }
359 
GetIncludeInlayVariableTypeHintsWhenTypeMatchesName()360     bool GetIncludeInlayVariableTypeHintsWhenTypeMatchesName() const
361     {
362         return includeInlayVariableTypeHintsWhenTypeMatchesName_;
363     }
364 
GetIncludeInlayPropertyDeclarationTypeHints()365     bool GetIncludeInlayPropertyDeclarationTypeHints() const
366     {
367         return includeInlayPropertyDeclarationTypeHints_;
368     }
369 
GetIncludeInlayFunctionLikeReturnTypeHints()370     bool GetIncludeInlayFunctionLikeReturnTypeHints() const
371     {
372         return includeInlayFunctionLikeReturnTypeHints_;
373     }
374 
GetIncludeInlayEnumMemberValueHints()375     bool GetIncludeInlayEnumMemberValueHints() const
376     {
377         return includeInlayEnumMemberValueHints_;
378     }
379 
GetAllowRenameOfImportPath()380     bool GetAllowRenameOfImportPath() const
381     {
382         return allowRenameOfImportPath_;
383     }
384 };
385 
386 }  // namespace ark::es2panda::lsp
387 
388 #endif