1
1
import { Range } from "vscode-languageserver/node" ;
2
2
import * as es from 'estree' ;
3
3
4
- // Note that the order the enum fields appear in determine the order they are displayed in the autocomplete list
4
+ /**
5
+ * Enum for differentiating between types of autocomplete, and also used for sorting the autocomplete items within the autocomplete list
6
+ */
5
7
export enum AUTOCOMPLETE_TYPES {
6
- BUILTIN ,
8
+ BUILTIN ,
7
9
KEYWORD ,
8
- SYMBOL ,
9
- MODULE
10
+ SYMBOL ,
11
+ MODULE
10
12
}
11
13
12
14
export enum NODES {
@@ -46,55 +48,141 @@ export enum EXPRESSIONS {
46
48
LAMBDA = "ArrowFunctionExpression"
47
49
}
48
50
51
+ /**
52
+ * Stores information about how that symbol was declared
53
+ */
49
54
export interface DeclarationSymbol {
55
+ /**
56
+ * Name of the symbol, taken from the identifier
57
+ */
50
58
name : string ,
59
+ /**
60
+ * Scope where the symbol can be used
61
+ * Defined as a SourceLocation object, which has 1-index lines
62
+ */
51
63
scope : es . SourceLocation ,
64
+ /**
65
+ * Meta information about the declaration
66
+ * If a constant is declared with a lambda, it will be assigned func
67
+ * If a let is declared with a lambda, it will still be assigned let as it can be reassigned later on
68
+ */
52
69
meta : "const" | "let" | "func" ,
70
+ /**
71
+ * More meta information about the declaration
72
+ * Has some overlap with `meta`, could be combined in the future
73
+ */
53
74
declarationKind : DeclarationKind ,
75
+ /**
76
+ * Range used only for highlighting purposes in DocumentSymbols, not really used anywhere else
77
+ */
54
78
range : Range ,
79
+ /**
80
+ * Range representing the location for the identifier of this symbol.
81
+ */
55
82
selectionRange : Range ,
83
+ /**
84
+ * Used for functions and lambdas to process child symbols in DocumentSymbols
85
+ */
56
86
parameters ?: Array < ParameterSymbol > ,
87
+ /**
88
+ * Flag whether to show this symbol in DocumentSymbols
89
+ * As of now, only lambda and function params have this flag set to true, as they are already in the children of the function symbol
90
+ */
57
91
showInDocumentSymbols ?: boolean ;
92
+ /**
93
+ * Flags whether this symbol has been used or not.
94
+ * Default should be set to true, then when an identifier for this declaration is found, flag can be set to false
95
+ * Right now this check occurs in the identifierRule when parsing for error diagnostics
96
+ */
58
97
unused : boolean
59
98
}
60
99
61
100
export interface ParameterSymbol extends DeclarationSymbol {
101
+ /**
102
+ * Flag for whether this symbol is a rest element or not. Used for some diagnostics.
103
+ */
62
104
isRestElement : boolean
63
105
}
64
106
65
107
export interface ImportedSymbol extends DeclarationSymbol {
108
+ /**
109
+ * String representing the module name where this symbol was imported from
110
+ */
66
111
module_name : string ,
112
+ /**
113
+ * String representing the actual defined name of this symbol in the module
114
+ * This should be ImportSpecifier.imported.name
115
+ * Not to be confused with ImportedSpecifier.local.name, which is the name for the DocumentSymbol this inherits from
116
+ */
67
117
real_name : string
68
118
}
69
119
120
+ /**
121
+ * Represents documentation scraped from Source Academy docs
122
+ */
70
123
export interface Documentation {
124
+ /**
125
+ * The name of the function/constant
126
+ */
71
127
label : string ,
128
+ /**
129
+ * Title of the description for the documentation
130
+ */
72
131
title : string ,
132
+ /**
133
+ * The whole description of this documentation
134
+ */
73
135
description : string ,
136
+ /**
137
+ * Meta information whether this is a constant or a function
138
+ */
74
139
meta : "const" | "func" ,
140
+ /**
141
+ * String array of parameters if this is a function
142
+ */
75
143
parameters ?: string [ ] ,
144
+ /**
145
+ * Strings for names of optional parameters
146
+ */
76
147
optional_params ?: string [ ] ,
77
- hasRestElement ? : boolean
148
+ /**
149
+ * Flag whether the last parameter is a rest element
150
+ * If so the function can take in any amount of parameters after the last one
151
+ */
152
+ hasRestElement ?: boolean
78
153
}
79
154
155
+ /**
156
+ * Interface for data to be stored within CompletionItems
157
+ */
80
158
export interface CompletionItemData {
159
+ /**
160
+ * Type of autocomplete
161
+ */
81
162
type : AUTOCOMPLETE_TYPES ,
82
- idx : number
163
+ /**
164
+ * Module name if AutoComplete comes from a Module, used for generating auto imports
165
+ */
83
166
module_name ?: string ,
167
+ /**
168
+ * String array if autocomplete is a function, used for generating autocomplete parameter snippets
169
+ */
84
170
parameters ?: string [ ] ,
85
- optional_params ?: string [ ] ,
86
- hasRestElement ?: boolean
171
+ /**
172
+ * String array of optional parameters, used to ignore parameters in autocomplete snippet
173
+ */
174
+ optional_params ?: string [ ]
87
175
}
88
176
89
177
90
178
// Taken from js-slang
91
179
export enum DeclarationKind {
92
- KIND_IMPORT = 'import' ,
93
- KIND_FUNCTION = 'func' ,
94
- KIND_LET = 'let' ,
95
- KIND_PARAM = 'param' ,
96
- KIND_CONST = 'const' ,
97
- KIND_KEYWORD = 'keyword'
180
+ KIND_IMPORT = 'import' ,
181
+ KIND_FUNCTION = 'func' ,
182
+ KIND_LET = 'let' ,
183
+ KIND_PARAM = 'param' ,
184
+ KIND_CONST = 'const' ,
185
+ KIND_KEYWORD = 'keyword'
98
186
}
99
187
100
188
export enum Chapter {
@@ -104,7 +192,16 @@ export enum Chapter {
104
192
SOURCE_4 = 4 ,
105
193
}
106
194
195
+ /**
196
+ * Context for the file being edited
197
+ */
107
198
export interface Context {
199
+ /**
200
+ * Source chapter for this file
201
+ */
108
202
chapter : Chapter ,
203
+ /**
204
+ * Number of lines of text being prepended to the file
205
+ */
109
206
prepend ?: number
110
207
}
0 commit comments