11import { Range } from "vscode-languageserver/node" ;
22import * as es from 'estree' ;
33
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+ */
57export enum AUTOCOMPLETE_TYPES {
6- BUILTIN ,
8+ BUILTIN ,
79 KEYWORD ,
8- SYMBOL ,
9- MODULE
10+ SYMBOL ,
11+ MODULE
1012}
1113
1214export enum NODES {
@@ -46,55 +48,141 @@ export enum EXPRESSIONS {
4648 LAMBDA = "ArrowFunctionExpression"
4749}
4850
51+ /**
52+ * Stores information about how that symbol was declared
53+ */
4954export interface DeclarationSymbol {
55+ /**
56+ * Name of the symbol, taken from the identifier
57+ */
5058 name : string ,
59+ /**
60+ * Scope where the symbol can be used
61+ * Defined as a SourceLocation object, which has 1-index lines
62+ */
5163 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+ */
5269 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+ */
5374 declarationKind : DeclarationKind ,
75+ /**
76+ * Range used only for highlighting purposes in DocumentSymbols, not really used anywhere else
77+ */
5478 range : Range ,
79+ /**
80+ * Range representing the location for the identifier of this symbol.
81+ */
5582 selectionRange : Range ,
83+ /**
84+ * Used for functions and lambdas to process child symbols in DocumentSymbols
85+ */
5686 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+ */
5791 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+ */
5897 unused : boolean
5998}
6099
61100export interface ParameterSymbol extends DeclarationSymbol {
101+ /**
102+ * Flag for whether this symbol is a rest element or not. Used for some diagnostics.
103+ */
62104 isRestElement : boolean
63105}
64106
65107export interface ImportedSymbol extends DeclarationSymbol {
108+ /**
109+ * String representing the module name where this symbol was imported from
110+ */
66111 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+ */
67117 real_name : string
68118}
69119
120+ /**
121+ * Represents documentation scraped from Source Academy docs
122+ */
70123export interface Documentation {
124+ /**
125+ * The name of the function/constant
126+ */
71127 label : string ,
128+ /**
129+ * Title of the description for the documentation
130+ */
72131 title : string ,
132+ /**
133+ * The whole description of this documentation
134+ */
73135 description : string ,
136+ /**
137+ * Meta information whether this is a constant or a function
138+ */
74139 meta : "const" | "func" ,
140+ /**
141+ * String array of parameters if this is a function
142+ */
75143 parameters ?: string [ ] ,
144+ /**
145+ * Strings for names of optional parameters
146+ */
76147 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
78153}
79154
155+ /**
156+ * Interface for data to be stored within CompletionItems
157+ */
80158export interface CompletionItemData {
159+ /**
160+ * Type of autocomplete
161+ */
81162 type : AUTOCOMPLETE_TYPES ,
82- idx : number
163+ /**
164+ * Module name if AutoComplete comes from a Module, used for generating auto imports
165+ */
83166 module_name ?: string ,
167+ /**
168+ * String array if autocomplete is a function, used for generating autocomplete parameter snippets
169+ */
84170 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 [ ]
87175}
88176
89177
90178// Taken from js-slang
91179export 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'
98186}
99187
100188export enum Chapter {
@@ -104,7 +192,16 @@ export enum Chapter {
104192 SOURCE_4 = 4 ,
105193}
106194
195+ /**
196+ * Context for the file being edited
197+ */
107198export interface Context {
199+ /**
200+ * Source chapter for this file
201+ */
108202 chapter : Chapter ,
203+ /**
204+ * Number of lines of text being prepended to the file
205+ */
109206 prepend ?: number
110207}
0 commit comments