Comparing version 1.1.16 to 2.0.0
@@ -5,3 +5,4 @@ { | ||
"node": true, | ||
"es6": true | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
@@ -12,4 +13,2 @@ "extends": [ | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:react/recommended", | ||
"plugin:jsx-a11y/recommended", | ||
"plugin:jsdoc/recommended" | ||
@@ -26,3 +25,3 @@ ], | ||
"ecmaFeatures": { | ||
"jsx": true | ||
"jsx": false | ||
}, | ||
@@ -34,4 +33,2 @@ "ecmaVersion": 8 | ||
"@typescript-eslint/tslint", | ||
"react", | ||
"jsx-a11y", | ||
"jsdoc", | ||
@@ -426,8 +423,3 @@ "prefer-arrow", | ||
"no-return-await": "error", | ||
"no-shadow": [ | ||
"error", | ||
{ | ||
"hoist": "all" | ||
} | ||
], | ||
"no-shadow": "off", | ||
"no-trailing-spaces": "error", | ||
@@ -472,124 +464,2 @@ "no-undef-init": "error", | ||
"indent": "off", | ||
"react/no-unescaped-entities": "off", | ||
"react/forbid-foreign-prop-types": [ | ||
"warn", | ||
{ | ||
"allowInPropTypes": true | ||
} | ||
], | ||
"react/jsx-no-comment-textnodes": [ | ||
"warn" | ||
], | ||
"react/jsx-no-duplicate-props": [ | ||
"warn" | ||
], | ||
"react/jsx-no-target-blank": [ | ||
"warn" | ||
], | ||
"react/jsx-no-undef": [ | ||
"error" | ||
], | ||
"react/jsx-pascal-case": [ | ||
"warn", | ||
{ | ||
"allowAllCaps": true, | ||
"ignore": [] | ||
} | ||
], | ||
"react/jsx-uses-react": [ | ||
"warn" | ||
], | ||
"react/jsx-uses-vars": [ | ||
"warn" | ||
], | ||
"react/no-danger-with-children": [ | ||
"warn" | ||
], | ||
"react/no-direct-mutation-state": [ | ||
"warn" | ||
], | ||
"react/no-is-mounted": [ | ||
"warn" | ||
], | ||
"react/no-typos": [ | ||
"error" | ||
], | ||
"react/react-in-jsx-scope": [ | ||
"error" | ||
], | ||
"react/require-render-return": [ | ||
"error" | ||
], | ||
"react/style-prop-object": [ | ||
"warn" | ||
], | ||
"react/display-name": ["off", { "ignoreTranspilerName": false }], | ||
"jsx-a11y/accessible-emoji": [ | ||
"warn" | ||
], | ||
"jsx-a11y/alt-text": [ | ||
"warn" | ||
], | ||
"jsx-a11y/anchor-has-content": [ | ||
"warn" | ||
], | ||
"jsx-a11y/anchor-is-valid": [ | ||
"warn", | ||
{ | ||
"aspects": [ | ||
"noHref", | ||
"invalidHref" | ||
] | ||
} | ||
], | ||
"jsx-a11y/aria-activedescendant-has-tabindex": [ | ||
"warn" | ||
], | ||
"jsx-a11y/aria-props": [ | ||
"warn" | ||
], | ||
"jsx-a11y/aria-proptypes": [ | ||
"warn" | ||
], | ||
"jsx-a11y/aria-role": [ | ||
"warn", | ||
{ | ||
"ignoreNonDOM": true | ||
} | ||
], | ||
"jsx-a11y/aria-unsupported-elements": [ | ||
"warn" | ||
], | ||
"jsx-a11y/heading-has-content": [ | ||
"warn" | ||
], | ||
"jsx-a11y/iframe-has-title": [ | ||
"warn" | ||
], | ||
"jsx-a11y/img-redundant-alt": [ | ||
"warn" | ||
], | ||
"jsx-a11y/no-access-key": [ | ||
"warn" | ||
], | ||
"jsx-a11y/no-distracting-elements": [ | ||
"warn" | ||
], | ||
"jsx-a11y/no-redundant-roles": [ | ||
"warn" | ||
], | ||
"jsx-a11y/role-has-required-aria-props": [ | ||
"warn" | ||
], | ||
"jsx-a11y/role-supports-aria-props": [ | ||
"warn" | ||
], | ||
"jsx-a11y/scope": [ | ||
"warn" | ||
], | ||
"jsx-a11y/no-noninteractive-element-interactions": "off", | ||
"jsx-a11y/no-noninteractive-tabindex": "off", | ||
"jsx-a11y/no-autofocus": [ 2, { | ||
"ignoreNonDOM": true | ||
}], | ||
"@typescript-eslint/no-unused-vars": [ | ||
@@ -617,7 +487,11 @@ "warn", | ||
], | ||
"@typescript-eslint/indent": ["error", 4, { | ||
"ignoreComments": true, | ||
"SwitchCase": 1, | ||
"MemberExpression": 1 | ||
}], | ||
"@typescript-eslint/indent": [ | ||
"error", | ||
4, | ||
{ | ||
"ignoreComments": true, | ||
"SwitchCase": 1, | ||
"MemberExpression": 1 | ||
} | ||
], | ||
"@typescript-eslint/interface-name-prefix": "off", | ||
@@ -674,2 +548,9 @@ "@typescript-eslint/member-delimiter-style": [ | ||
"@typescript-eslint/prefer-regexp-exec": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-shadow": [ | ||
"error", | ||
{ | ||
"ignoreTypeValueShadow": true | ||
} | ||
], | ||
"jsdoc/check-alignment": "error", | ||
@@ -676,0 +557,0 @@ "jsdoc/check-indentation": "off", |
@@ -10,3 +10,3 @@ 'use strict'; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,13 +0,13 @@ | ||
import { Parser, ParserRuleContext } from 'antlr4ts'; | ||
import { Parser, ParserRuleContext } from "antlr4ts"; | ||
export declare type TokenList = number[]; | ||
export declare type CandidateRule = { | ||
export declare type RuleList = number[]; | ||
export interface CandidateRule { | ||
startTokenIndex: number; | ||
ruleList: RuleList; | ||
}; | ||
export declare type RuleWithStartToken = { | ||
} | ||
export interface RuleWithStartToken { | ||
startTokenIndex: number; | ||
ruleIndex: number; | ||
}; | ||
} | ||
export declare type RuleWithStartTokenList = RuleWithStartToken[]; | ||
export declare type RuleList = number[]; | ||
export declare class CandidatesCollection { | ||
@@ -18,2 +18,4 @@ tokens: Map<number, TokenList>; | ||
export declare class CodeCompletionCore { | ||
private static followSetsByATN; | ||
private static atnStateTypeMap; | ||
showResult: boolean; | ||
@@ -36,3 +38,2 @@ showDebugOutput: boolean; | ||
private candidates; | ||
private static followSetsByATN; | ||
constructor(parser: Parser); | ||
@@ -47,3 +48,2 @@ collectCandidates(caretTokenIndex: number, context?: ParserRuleContext): CandidatesCollection; | ||
private processRule; | ||
private atnStateTypeMap; | ||
private generateBaseDescription; | ||
@@ -50,0 +50,0 @@ private printDescription; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,3 +14,2 @@ exports.CodeCompletionCore = exports.CandidatesCollection = void 0; | ||
exports.CandidatesCollection = CandidatesCollection; | ||
; | ||
class FollowSetWithPath { | ||
@@ -22,9 +21,4 @@ constructor() { | ||
} | ||
; | ||
class FollowSetsHolder { | ||
} | ||
; | ||
class PipelineEntry { | ||
} | ||
; | ||
class CodeCompletionCore { | ||
@@ -41,17 +35,2 @@ constructor(parser) { | ||
this.candidates = new CandidatesCollection(); | ||
this.atnStateTypeMap = [ | ||
"invalid", | ||
"basic", | ||
"rule start", | ||
"block start", | ||
"plus block start", | ||
"star block start", | ||
"token start", | ||
"rule stop", | ||
"block end", | ||
"star loop back", | ||
"star loop entry", | ||
"plus loop back", | ||
"loop end" | ||
]; | ||
this.parser = parser; | ||
@@ -71,3 +50,3 @@ this.atn = parser.atn; | ||
this.tokenStartIndex = context ? context.start.tokenIndex : 0; | ||
let tokenStream = this.parser.inputStream; | ||
const tokenStream = this.parser.inputStream; | ||
this.tokens = []; | ||
@@ -79,19 +58,19 @@ let offset = this.tokenStartIndex; | ||
this.tokens.push(token); | ||
if (token.tokenIndex >= caretTokenIndex || token.type == antlr4ts_1.Token.EOF) { | ||
if (token.tokenIndex >= caretTokenIndex || token.type === antlr4ts_1.Token.EOF) { | ||
break; | ||
} | ||
} | ||
if (token.type == antlr4ts_1.Token.EOF) { | ||
if (token.type === antlr4ts_1.Token.EOF) { | ||
break; | ||
} | ||
} | ||
let callStack = []; | ||
let startRule = context ? context.ruleIndex : 0; | ||
const callStack = []; | ||
const startRule = context ? context.ruleIndex : 0; | ||
this.processRule(this.atn.ruleToStartState[startRule], 0, callStack, 0, 0); | ||
if (this.showResult) { | ||
console.log("States processed: " + this.statesProcessed); | ||
console.log(`States processed: ${this.statesProcessed}`); | ||
console.log("\n\nCollected rules:\n"); | ||
for (let rule of this.candidates.rules) { | ||
for (const rule of this.candidates.rules) { | ||
let path = ""; | ||
for (let token of rule[1].ruleList) { | ||
for (const token of rule[1].ruleList) { | ||
path += this.ruleNames[token] + " "; | ||
@@ -102,10 +81,11 @@ } | ||
const sortedTokens = new Set(); | ||
for (let token of this.candidates.tokens) { | ||
for (const token of this.candidates.tokens) { | ||
let value = this.vocabulary.getDisplayName(token[0]); | ||
for (let following of token[1]) | ||
for (const following of token[1]) { | ||
value += " " + this.vocabulary.getDisplayName(following); | ||
} | ||
sortedTokens.add(value); | ||
} | ||
console.log("\n\nCollected tokens:\n"); | ||
for (let symbol of sortedTokens) { | ||
for (const symbol of sortedTokens) { | ||
console.log(symbol); | ||
@@ -121,3 +101,3 @@ } | ||
translateStackToRuleIndex(ruleWithStartTokenList) { | ||
if (this.preferredRules.size == 0) { | ||
if (this.preferredRules.size === 0) { | ||
return false; | ||
@@ -144,6 +124,6 @@ } | ||
if (this.preferredRules.has(ruleIndex)) { | ||
const path = ruleWithStartTokenList.slice(0, i).map(({ ruleIndex }) => ruleIndex); | ||
const path = ruleWithStartTokenList.slice(0, i).map(({ ruleIndex: candidate }) => candidate); | ||
let addNew = true; | ||
for (let rule of this.candidates.rules) { | ||
if (rule[0] != ruleIndex || rule[1].ruleList.length != path.length) { | ||
for (const rule of this.candidates.rules) { | ||
if (rule[0] !== ruleIndex || rule[1].ruleList.length !== path.length) { | ||
continue; | ||
@@ -174,15 +154,17 @@ } | ||
const state = pipeline.pop(); | ||
for (let transition of state.getTransitions()) { | ||
if (transition.serializationType == 5) { | ||
if (!transition.isEpsilon) { | ||
let list = transition.label.toArray(); | ||
if (list.length == 1 && !this.ignoredTokens.has(list[0])) { | ||
result.push(list[0]); | ||
pipeline.push(transition.target); | ||
if (state) { | ||
state.getTransitions().forEach((outgoing) => { | ||
if (outgoing.serializationType === 5) { | ||
if (!outgoing.isEpsilon) { | ||
const list = outgoing.label.toArray(); | ||
if (list.length === 1 && !this.ignoredTokens.has(list[0])) { | ||
result.push(list[0]); | ||
pipeline.push(outgoing.target); | ||
} | ||
} | ||
else { | ||
pipeline.push(outgoing.target); | ||
} | ||
} | ||
else { | ||
pipeline.push(transition.target); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -200,8 +182,8 @@ } | ||
collectFollowSets(s, stopState, followSets, stateStack, ruleStack) { | ||
if (stateStack.find(x => x == s)) { | ||
if (stateStack.find((x) => x === s)) { | ||
return; | ||
} | ||
stateStack.push(s); | ||
if (s == stopState || s.stateType == atn_1.ATNStateType.RULE_STOP) { | ||
let set = new FollowSetWithPath(); | ||
if (s === stopState || s.stateType === atn_1.ATNStateType.RULE_STOP) { | ||
const set = new FollowSetWithPath(); | ||
set.intervals = IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.EPSILON); | ||
@@ -213,6 +195,6 @@ set.path = ruleStack.slice(); | ||
} | ||
for (let transition of s.getTransitions()) { | ||
if (transition.serializationType == 3) { | ||
let ruleTransition = transition; | ||
if (ruleStack.indexOf(ruleTransition.target.ruleIndex) != -1) { | ||
for (const transition of s.getTransitions()) { | ||
if (transition.serializationType === 3) { | ||
const ruleTransition = transition; | ||
if (ruleStack.indexOf(ruleTransition.target.ruleIndex) !== -1) { | ||
continue; | ||
@@ -224,3 +206,3 @@ } | ||
} | ||
else if (transition.serializationType == 4) { | ||
else if (transition.serializationType === 4) { | ||
if (this.checkPredicate(transition)) { | ||
@@ -233,4 +215,4 @@ this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
} | ||
else if (transition.serializationType == 9) { | ||
let set = new FollowSetWithPath(); | ||
else if (transition.serializationType === 9) { | ||
const set = new FollowSetWithPath(); | ||
set.intervals = IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType); | ||
@@ -243,3 +225,3 @@ set.path = ruleStack.slice(); | ||
if (label && label.size > 0) { | ||
if (transition.serializationType == 8) { | ||
if (transition.serializationType === 8) { | ||
label = label.complement(IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType)); | ||
@@ -281,6 +263,6 @@ } | ||
setsPerState.set(startState.stateNumber, followSets); | ||
let stop = this.atn.ruleToStopState[startState.ruleIndex]; | ||
const stop = this.atn.ruleToStopState[startState.ruleIndex]; | ||
followSets.sets = this.determineFollowSets(startState, stop); | ||
let combined = new IntervalSet_1.IntervalSet(); | ||
for (let set of followSets.sets) { | ||
const combined = new IntervalSet_1.IntervalSet(); | ||
for (const set of followSets.sets) { | ||
combined.addAll(set.intervals); | ||
@@ -300,5 +282,5 @@ } | ||
else { | ||
for (let set of followSets.sets) { | ||
for (const set of followSets.sets) { | ||
const fullPath = callStack.slice(); | ||
const followSetPath = set.path.map(path => ({ | ||
const followSetPath = set.path.map((path) => ({ | ||
startTokenIndex, | ||
@@ -309,3 +291,3 @@ ruleIndex: path, | ||
if (!this.translateStackToRuleIndex(fullPath)) { | ||
for (let symbol of set.intervals.toArray()) | ||
for (const symbol of set.intervals.toArray()) { | ||
if (!this.ignoredTokens.has(symbol)) { | ||
@@ -319,3 +301,3 @@ if (this.showDebugOutput) { | ||
else { | ||
if (this.candidates.tokens.get(symbol) != set.following) { | ||
if (this.candidates.tokens.get(symbol) !== set.following) { | ||
this.candidates.tokens.set(symbol, []); | ||
@@ -325,2 +307,3 @@ } | ||
} | ||
} | ||
} | ||
@@ -344,3 +327,3 @@ } | ||
let currentEntry; | ||
statePipeline.push({ state: startState, tokenListIndex: tokenListIndex }); | ||
statePipeline.push({ state: startState, tokenListIndex }); | ||
while (statePipeline.length > 0) { | ||
@@ -353,6 +336,7 @@ currentEntry = statePipeline.pop(); | ||
this.printDescription(indentation, currentEntry.state, this.generateBaseDescription(currentEntry.state), currentEntry.tokenListIndex); | ||
if (this.showRuleStack) | ||
if (this.showRuleStack) { | ||
this.printRuleState(callStack); | ||
} | ||
} | ||
if (currentEntry.state.stateType == atn_1.ATNStateType.RULE_STOP) { | ||
if (currentEntry.state.stateType === atn_1.ATNStateType.RULE_STOP) { | ||
result.add(currentEntry.tokenListIndex); | ||
@@ -362,3 +346,3 @@ continue; | ||
const transitions = currentEntry.state.getTransitions(); | ||
for (let transition of transitions) { | ||
for (const transition of transitions) { | ||
switch (transition.serializationType) { | ||
@@ -368,6 +352,6 @@ case 3: { | ||
const endStatus = this.processRule(transition.target, currentEntry.tokenListIndex, callStack, ruleTransition.precedence, indentation + 1); | ||
for (let position of endStatus) { | ||
for (const position of endStatus) { | ||
statePipeline.push({ | ||
state: transition.followState, | ||
tokenListIndex: position | ||
tokenListIndex: position, | ||
}); | ||
@@ -378,7 +362,8 @@ } | ||
case 4: { | ||
if (this.checkPredicate(transition)) | ||
if (this.checkPredicate(transition)) { | ||
statePipeline.push({ | ||
state: transition.target, | ||
tokenListIndex: currentEntry.tokenListIndex | ||
tokenListIndex: currentEntry.tokenListIndex, | ||
}); | ||
} | ||
break; | ||
@@ -388,7 +373,8 @@ } | ||
const predTransition = transition; | ||
if (predTransition.precedence >= this.precedenceStack[this.precedenceStack.length - 1]) | ||
if (predTransition.precedence >= this.precedenceStack[this.precedenceStack.length - 1]) { | ||
statePipeline.push({ | ||
state: transition.target, | ||
tokenListIndex: currentEntry.tokenListIndex | ||
tokenListIndex: currentEntry.tokenListIndex, | ||
}); | ||
} | ||
break; | ||
@@ -399,3 +385,3 @@ } | ||
if (!this.translateStackToRuleIndex(callStack)) { | ||
for (let token of IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType) | ||
for (const token of IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType) | ||
.toArray()) { | ||
@@ -411,3 +397,3 @@ if (!this.ignoredTokens.has(token)) { | ||
state: transition.target, | ||
tokenListIndex: currentEntry.tokenListIndex + 1 | ||
tokenListIndex: currentEntry.tokenListIndex + 1, | ||
}); | ||
@@ -421,3 +407,3 @@ } | ||
state: transition.target, | ||
tokenListIndex: currentEntry.tokenListIndex | ||
tokenListIndex: currentEntry.tokenListIndex, | ||
}); | ||
@@ -428,3 +414,3 @@ continue; | ||
if (set && set.size > 0) { | ||
if (transition.serializationType == 8) { | ||
if (transition.serializationType === 8) { | ||
set = set.complement(IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType)); | ||
@@ -434,5 +420,5 @@ } | ||
if (!this.translateStackToRuleIndex(callStack)) { | ||
let list = set.toArray(); | ||
let addFollowing = list.length == 1; | ||
for (let symbol of list) | ||
const list = set.toArray(); | ||
const addFollowing = list.length === 1; | ||
for (const symbol of list) { | ||
if (!this.ignoredTokens.has(symbol)) { | ||
@@ -449,2 +435,3 @@ if (this.showDebugOutput) { | ||
} | ||
} | ||
} | ||
@@ -459,3 +446,3 @@ } | ||
state: transition.target, | ||
tokenListIndex: currentEntry.tokenListIndex + 1 | ||
tokenListIndex: currentEntry.tokenListIndex + 1, | ||
}); | ||
@@ -477,5 +464,5 @@ } | ||
generateBaseDescription(state) { | ||
const stateValue = state.stateNumber == atn_1.ATNState.INVALID_STATE_NUMBER ? "Invalid" : state.stateNumber; | ||
return "[" + stateValue + " " + this.atnStateTypeMap[state.stateType] + "] in " + | ||
this.ruleNames[state.ruleIndex]; | ||
const stateValue = state.stateNumber === atn_1.ATNState.INVALID_STATE_NUMBER ? "Invalid" : state.stateNumber; | ||
return `[${stateValue} ${CodeCompletionCore.atnStateTypeMap[state.stateType]}] in ` + | ||
`${this.ruleNames[state.ruleIndex]}`; | ||
} | ||
@@ -487,5 +474,5 @@ printDescription(indentation, state, baseDescription, tokenIndex) { | ||
if (this.debugOutputWithTransitions) { | ||
for (let transition of state.getTransitions()) { | ||
for (const transition of state.getTransitions()) { | ||
let labels = ""; | ||
let symbols = transition.label ? transition.label.toArray() : []; | ||
const symbols = transition.label ? transition.label.toArray() : []; | ||
if (symbols.length > 2) { | ||
@@ -496,3 +483,3 @@ labels = this.vocabulary.getDisplayName(symbols[0]) + " .. " + | ||
else { | ||
for (let symbol of symbols) { | ||
for (const symbol of symbols) { | ||
if (labels.length > 0) { | ||
@@ -504,15 +491,15 @@ labels += ", "; | ||
} | ||
if (labels.length == 0) { | ||
if (labels.length === 0) { | ||
labels = "ε"; | ||
} | ||
transitionDescription += "\n" + indent + "\t(" + labels + ") " + "[" + | ||
transition.target.stateNumber + " " + this.atnStateTypeMap[transition.target.stateType] + "] in " + | ||
this.ruleNames[transition.target.ruleIndex]; | ||
transitionDescription += `\n${indent}\t(${labels}) [${transition.target.stateNumber} ` + | ||
`${CodeCompletionCore.atnStateTypeMap[transition.target.stateType]}] in ` + | ||
`${this.ruleNames[transition.target.ruleIndex]}`; | ||
} | ||
} | ||
if (tokenIndex >= this.tokens.length - 1) { | ||
output += "<<" + this.tokenStartIndex + tokenIndex + ">> "; | ||
output += `<<${this.tokenStartIndex + tokenIndex}>> `; | ||
} | ||
else { | ||
output += "<" + this.tokenStartIndex + tokenIndex + "> "; | ||
output += `<${this.tokenStartIndex + tokenIndex}> `; | ||
} | ||
@@ -522,7 +509,7 @@ console.log(output + "Current state: " + baseDescription + transitionDescription); | ||
printRuleState(stack) { | ||
if (stack.length == 0) { | ||
if (stack.length === 0) { | ||
console.log("<empty stack>"); | ||
return; | ||
} | ||
for (let rule of stack) { | ||
for (const rule of stack) { | ||
console.log(this.ruleNames[rule.ruleIndex]); | ||
@@ -534,2 +521,17 @@ } | ||
CodeCompletionCore.followSetsByATN = new Map(); | ||
CodeCompletionCore.atnStateTypeMap = [ | ||
"invalid", | ||
"basic", | ||
"rule start", | ||
"block start", | ||
"plus block start", | ||
"star block start", | ||
"token start", | ||
"rule stop", | ||
"block end", | ||
"star loop back", | ||
"star loop entry", | ||
"plus loop back", | ||
"loop end", | ||
]; | ||
//# sourceMappingURL=CodeCompletionCore.js.map |
@@ -1,2 +0,2 @@ | ||
import { ParseTree } from 'antlr4ts/tree/ParseTree'; | ||
import { ParseTree } from "antlr4ts/tree/ParseTree"; | ||
export declare class DuplicateSymbolError extends Error { | ||
@@ -37,6 +37,2 @@ } | ||
export declare class FundamentalType implements Type { | ||
name: string; | ||
get baseTypes(): Type[]; | ||
get kind(): TypeKind; | ||
get reference(): ReferenceKind; | ||
static readonly integerType: FundamentalType; | ||
@@ -47,9 +43,14 @@ static readonly floatType: FundamentalType; | ||
static readonly dateType: FundamentalType; | ||
constructor(name: string, typeKind: TypeKind, referenceKind: ReferenceKind); | ||
name: string; | ||
private typeKind; | ||
private referenceKind; | ||
constructor(name: string, typeKind: TypeKind, referenceKind: ReferenceKind); | ||
get baseTypes(): Type[]; | ||
get kind(): TypeKind; | ||
get reference(): ReferenceKind; | ||
} | ||
export declare class Symbol { | ||
name: string; | ||
context: ParseTree | undefined; | ||
context?: ParseTree; | ||
private theParent?; | ||
constructor(name?: string); | ||
@@ -64,3 +65,3 @@ setParent(parent: Symbol | undefined): void; | ||
removeFromParent(): void; | ||
resolve(name: string, localOnly?: boolean): Symbol | undefined; | ||
resolve(name: string, localOnly?: boolean): Promise<Symbol | undefined>; | ||
get root(): Symbol | undefined; | ||
@@ -71,3 +72,2 @@ get symbolTable(): SymbolTable | undefined; | ||
qualifiedName(separator?: string, full?: boolean, includeAnonymous?: boolean): string; | ||
protected _parent: Symbol | undefined; | ||
} | ||
@@ -82,6 +82,7 @@ export declare class TypedSymbol extends Symbol { | ||
get reference(): ReferenceKind; | ||
private targetType; | ||
constructor(name: string, target: Type); | ||
private targetType; | ||
} | ||
export declare class ScopedSymbol extends Symbol { | ||
private _children; | ||
constructor(name?: string); | ||
@@ -92,10 +93,10 @@ get children(): Symbol[]; | ||
removeSymbol(symbol: Symbol): void; | ||
getNestedSymbolsOfType<T extends Symbol>(t: new (...args: any[]) => T): T[]; | ||
getAllNestedSymbols(name?: string): Symbol[]; | ||
getSymbolsOfType<T extends Symbol>(t: new (...args: any[]) => T): T[]; | ||
getAllSymbols<T extends Symbol>(t: new (...args: any[]) => T, localOnly?: boolean): Set<Symbol>; | ||
resolve(name: string, localOnly?: boolean): Symbol | undefined; | ||
getNestedSymbolsOfType<T extends Symbol>(t: new (...args: any[]) => T): Promise<T[]>; | ||
getAllNestedSymbols(name?: string): Promise<Symbol[]>; | ||
getSymbolsOfType<T extends Symbol>(t: new (...args: any[]) => T): Promise<T[]>; | ||
getAllSymbols<T extends Symbol>(t: new (...args: any[]) => T, localOnly?: boolean): Promise<Symbol[]>; | ||
resolve(name: string, localOnly?: boolean): Promise<Symbol | undefined>; | ||
getTypedSymbols(localOnly?: boolean): TypedSymbol[]; | ||
getTypedSymbolNames(localOnly?: boolean): string[]; | ||
get directScopes(): ScopedSymbol[]; | ||
get directScopes(): Promise<ScopedSymbol[]>; | ||
symbolFromPath(path: string, separator?: string): Symbol | undefined; | ||
@@ -108,3 +109,2 @@ indexOfChild(child: Symbol): number; | ||
nextOf(child: Symbol): Symbol | undefined; | ||
private _children; | ||
} | ||
@@ -116,8 +116,8 @@ export declare class NamespaceSymbol extends ScopedSymbol { | ||
export declare class VariableSymbol extends TypedSymbol { | ||
value: any; | ||
constructor(name: string, value: any, type?: Type); | ||
value: any; | ||
} | ||
export declare class LiteralSymbol extends TypedSymbol { | ||
readonly value: any; | ||
constructor(name: string, value: any, type?: Type); | ||
readonly value: any; | ||
} | ||
@@ -127,6 +127,6 @@ export declare class ParameterSymbol extends VariableSymbol { | ||
export declare class RoutineSymbol extends ScopedSymbol { | ||
returnType: Type | undefined; | ||
private returnType?; | ||
constructor(name: string, returnType: Type); | ||
getVariables(localOnly?: boolean): VariableSymbol[]; | ||
getParameters(localOnly?: boolean): ParameterSymbol[]; | ||
getVariables(localOnly?: boolean): Promise<VariableSymbol[]>; | ||
getParameters(localOnly?: boolean): Promise<ParameterSymbol[]>; | ||
} | ||
@@ -144,9 +144,7 @@ export declare enum MethodFlags { | ||
visibility: MemberVisibility; | ||
constructor(name: string, returnType: Type); | ||
} | ||
export declare class FieldSymbol extends VariableSymbol { | ||
visibility: MemberVisibility; | ||
setter: MethodSymbol | undefined; | ||
getter: MethodSymbol | undefined; | ||
constructor(name: string, type: Type); | ||
setter?: MethodSymbol; | ||
getter?: MethodSymbol; | ||
} | ||
@@ -159,6 +157,6 @@ export declare class ClassSymbol extends ScopedSymbol implements Type { | ||
readonly superClasses: ClassSymbol[]; | ||
private referenceKind; | ||
constructor(name: string, referenceKind: ReferenceKind, ...superClass: ClassSymbol[]); | ||
getMethods(includeInherited?: boolean): MethodSymbol[]; | ||
getFields(includeInherited?: boolean): FieldSymbol[]; | ||
private referenceKind; | ||
getMethods(includeInherited?: boolean): Promise<MethodSymbol[]>; | ||
getFields(includeInherited?: boolean): Promise<FieldSymbol[]>; | ||
} | ||
@@ -171,7 +169,8 @@ export declare class ArrayType extends Symbol implements Type { | ||
readonly size: number; | ||
private referenceKind; | ||
constructor(name: string, referenceKind: ReferenceKind, elemType: Type, size?: number); | ||
private referenceKind; | ||
} | ||
export declare class SymbolTable extends ScopedSymbol { | ||
readonly options: SymbolTableOptions; | ||
protected dependencies: Set<SymbolTable>; | ||
constructor(name: string, options: SymbolTableOptions); | ||
@@ -186,7 +185,6 @@ clear(): void; | ||
addNewSymbolOfType<T extends Symbol>(t: new (...args: any[]) => T, parent: ScopedSymbol | undefined, ...args: any[]): T; | ||
addNewNamespaceFromPath(parent: ScopedSymbol | undefined, path: string, delimiter?: string): NamespaceSymbol; | ||
getAllSymbols<T extends Symbol>(t?: new (...args: any[]) => T, localOnly?: boolean): Set<Symbol>; | ||
symbolWithContext(context: ParseTree): Symbol | undefined; | ||
resolve(name: string, localOnly?: boolean): Symbol | undefined; | ||
protected dependencies: Set<SymbolTable>; | ||
addNewNamespaceFromPath(parent: ScopedSymbol | undefined, path: string, delimiter?: string): Promise<NamespaceSymbol>; | ||
getAllSymbols(type?: typeof Symbol, localOnly?: boolean): Promise<Symbol[]>; | ||
symbolWithContext(context: ParseTree): Promise<Symbol | undefined>; | ||
resolve(name: string, localOnly?: boolean): Promise<Symbol | undefined>; | ||
} |
@@ -1,2 +0,11 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,3 +16,2 @@ exports.SymbolTable = exports.ArrayType = exports.ClassSymbol = exports.FieldSymbol = exports.MethodSymbol = exports.MethodFlags = exports.RoutineSymbol = exports.ParameterSymbol = exports.LiteralSymbol = exports.VariableSymbol = exports.BlockSymbol = exports.NamespaceSymbol = exports.ScopedSymbol = exports.TypeAlias = exports.TypedSymbol = exports.Symbol = exports.FundamentalType = exports.ReferenceKind = exports.TypeKind = exports.MemberVisibility = exports.DuplicateSymbolError = void 0; | ||
exports.DuplicateSymbolError = DuplicateSymbolError; | ||
; | ||
var MemberVisibility; | ||
@@ -17,3 +25,2 @@ (function (MemberVisibility) { | ||
})(MemberVisibility = exports.MemberVisibility || (exports.MemberVisibility = {})); | ||
; | ||
var TypeKind; | ||
@@ -30,3 +37,2 @@ (function (TypeKind) { | ||
})(TypeKind = exports.TypeKind || (exports.TypeKind = {})); | ||
; | ||
var ReferenceKind; | ||
@@ -39,3 +45,2 @@ (function (ReferenceKind) { | ||
})(ReferenceKind = exports.ReferenceKind || (exports.ReferenceKind = {})); | ||
; | ||
class FundamentalType { | ||
@@ -47,5 +52,11 @@ constructor(name, typeKind, referenceKind) { | ||
} | ||
get baseTypes() { return []; } | ||
get kind() { return this.typeKind; } | ||
get reference() { return this.referenceKind; } | ||
get baseTypes() { | ||
return []; | ||
} | ||
get kind() { | ||
return this.typeKind; | ||
} | ||
get reference() { | ||
return this.referenceKind; | ||
} | ||
} | ||
@@ -64,10 +75,10 @@ exports.FundamentalType = FundamentalType; | ||
setParent(parent) { | ||
this._parent = parent; | ||
this.theParent = parent; | ||
} | ||
get parent() { | ||
return this._parent; | ||
return this.theParent; | ||
} | ||
get firstSibling() { | ||
if (this._parent instanceof ScopedSymbol) { | ||
return this._parent.firstChild; | ||
if (this.theParent instanceof ScopedSymbol) { | ||
return this.theParent.firstChild; | ||
} | ||
@@ -77,22 +88,16 @@ return this; | ||
get previousSibling() { | ||
if (!(this._parent instanceof ScopedSymbol)) { | ||
if (!(this.theParent instanceof ScopedSymbol)) { | ||
return this; | ||
} | ||
let result = this._parent.previousSiblingOf(this); | ||
if (result) { | ||
return result; | ||
} | ||
return this.theParent.previousSiblingOf(this); | ||
} | ||
get nextSibling() { | ||
if (!(this._parent instanceof ScopedSymbol)) { | ||
if (!(this.theParent instanceof ScopedSymbol)) { | ||
return this; | ||
} | ||
let result = this._parent.nextSiblingOf(this); | ||
if (result) { | ||
return result; | ||
} | ||
return this.theParent.nextSiblingOf(this); | ||
} | ||
get lastSibling() { | ||
if (this._parent instanceof ScopedSymbol) { | ||
return this._parent.lastChild; | ||
if (this.theParent instanceof ScopedSymbol) { | ||
return this.theParent.lastChild; | ||
} | ||
@@ -102,23 +107,28 @@ return this; | ||
get next() { | ||
if (this.parent instanceof ScopedSymbol) { | ||
return this.parent.nextOf(this); | ||
if (this.theParent instanceof ScopedSymbol) { | ||
return this.theParent.nextOf(this); | ||
} | ||
return undefined; | ||
} | ||
removeFromParent() { | ||
if (this._parent instanceof ScopedSymbol) { | ||
this._parent.removeSymbol(this); | ||
this._parent = undefined; | ||
if (this.theParent instanceof ScopedSymbol) { | ||
this.theParent.removeSymbol(this); | ||
this.theParent = undefined; | ||
} | ||
} | ||
resolve(name, localOnly = false) { | ||
if (this._parent instanceof ScopedSymbol) { | ||
return this._parent.resolve(name, localOnly); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.theParent instanceof ScopedSymbol) { | ||
return this.theParent.resolve(name, localOnly); | ||
} | ||
return Promise.resolve(undefined); | ||
}); | ||
} | ||
get root() { | ||
let run = this._parent; | ||
let run = this.theParent; | ||
while (run) { | ||
if (!run._parent || (run._parent instanceof SymbolTable)) | ||
if (!run.theParent || (run.theParent instanceof SymbolTable)) { | ||
return run; | ||
run = run._parent; | ||
} | ||
run = run.theParent; | ||
} | ||
@@ -131,7 +141,8 @@ return run; | ||
} | ||
let run = this._parent; | ||
let run = this.theParent; | ||
while (run) { | ||
if (run instanceof SymbolTable) | ||
if (run instanceof SymbolTable) { | ||
return run; | ||
run = run._parent; | ||
} | ||
run = run.theParent; | ||
} | ||
@@ -141,7 +152,8 @@ return undefined; | ||
getParentOfType(t) { | ||
let run = this._parent; | ||
let run = this.theParent; | ||
while (run) { | ||
if (run instanceof t) | ||
if (run instanceof t) { | ||
return run; | ||
run = run._parent; | ||
} | ||
run = run.theParent; | ||
} | ||
@@ -151,9 +163,10 @@ return undefined; | ||
get symbolPath() { | ||
let result = []; | ||
const result = []; | ||
let run = this; | ||
while (run) { | ||
result.push(run); | ||
if (!run._parent) | ||
if (!run.theParent) { | ||
break; | ||
run = run._parent; | ||
} | ||
run = run.theParent; | ||
} | ||
@@ -163,13 +176,15 @@ return result; | ||
qualifiedName(separator = ".", full = false, includeAnonymous = false) { | ||
if (!includeAnonymous && this.name.length == 0) | ||
if (!includeAnonymous && this.name.length === 0) { | ||
return ""; | ||
let result = this.name.length == 0 ? "<anonymous>" : this.name; | ||
let run = this._parent; | ||
} | ||
let result = this.name.length === 0 ? "<anonymous>" : this.name; | ||
let run = this.theParent; | ||
while (run) { | ||
if (includeAnonymous || run.name.length > 0) { | ||
result = (run.name.length == 0 ? "<anonymous>" : run.name) + separator + result; | ||
if (!full || !run._parent) | ||
break; | ||
result = (run.name.length === 0 ? "<anonymous>" : run.name) + separator + result; | ||
} | ||
run = run._parent; | ||
if (!full || !run.theParent) { | ||
break; | ||
} | ||
run = run.theParent; | ||
} | ||
@@ -180,3 +195,2 @@ return result; | ||
exports.Symbol = Symbol; | ||
; | ||
class TypedSymbol extends Symbol { | ||
@@ -189,3 +203,2 @@ constructor(name, type) { | ||
exports.TypedSymbol = TypedSymbol; | ||
; | ||
class TypeAlias extends Symbol { | ||
@@ -201,3 +214,2 @@ constructor(name, target) { | ||
exports.TypeAlias = TypeAlias; | ||
; | ||
class ScopedSymbol extends Symbol { | ||
@@ -216,20 +228,21 @@ constructor(name = "") { | ||
symbol.removeFromParent(); | ||
let symbolTable = this.symbolTable; | ||
const symbolTable = this.symbolTable; | ||
if (!symbolTable || !symbolTable.options.allowDuplicateSymbols) { | ||
for (let child of this._children) { | ||
if (child == symbol || (symbol.name.length > 0 && child.name == symbol.name)) { | ||
this.children.forEach((child) => { | ||
if (child === symbol || (symbol.name.length > 0 && child.name === symbol.name)) { | ||
let name = symbol.name; | ||
if (name.length == 0) | ||
if (name.length === 0) { | ||
name = "<anonymous>"; | ||
} | ||
throw new DuplicateSymbolError("Attempt to add duplicate symbol '" + name + "'"); | ||
} | ||
} | ||
}); | ||
} | ||
this._children.push(symbol); | ||
this.children.push(symbol); | ||
symbol.setParent(this); | ||
} | ||
removeSymbol(symbol) { | ||
let index = this._children.indexOf(symbol); | ||
const index = this.children.indexOf(symbol); | ||
if (index > -1) { | ||
this._children.splice(index, 1); | ||
this.children.splice(index, 1); | ||
symbol.setParent(undefined); | ||
@@ -239,61 +252,93 @@ } | ||
getNestedSymbolsOfType(t) { | ||
let result = []; | ||
for (let child of this._children) { | ||
if (child instanceof t) | ||
result.push(child); | ||
if (child instanceof ScopedSymbol) | ||
result.push(...child.getNestedSymbolsOfType(t)); | ||
} | ||
return result; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = []; | ||
const childPromises = []; | ||
this.children.forEach((child) => { | ||
if (child instanceof t) { | ||
result.push(child); | ||
} | ||
if (child instanceof ScopedSymbol) { | ||
childPromises.push(child.getNestedSymbolsOfType(t)); | ||
} | ||
}); | ||
const childSymbols = yield Promise.all(childPromises); | ||
childSymbols.forEach((entry) => { | ||
result.push(...entry); | ||
}); | ||
return result; | ||
}); | ||
} | ||
getAllNestedSymbols(name) { | ||
let result = []; | ||
for (let child of this._children) { | ||
if (!name || child.name == name) { | ||
result.push(child); | ||
} | ||
if (child instanceof ScopedSymbol) | ||
result.push(...child.getAllNestedSymbols(name)); | ||
} | ||
return result; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = []; | ||
const childPromises = []; | ||
this.children.forEach((child) => { | ||
if (!name || child.name === name) { | ||
result.push(child); | ||
} | ||
if (child instanceof ScopedSymbol) { | ||
childPromises.push(child.getAllNestedSymbols(name)); | ||
} | ||
}); | ||
const childSymbols = yield Promise.all(childPromises); | ||
childSymbols.forEach((entry) => { | ||
result.push(...entry); | ||
}); | ||
return result; | ||
}); | ||
} | ||
getSymbolsOfType(t) { | ||
let result = []; | ||
for (let child of this._children) { | ||
if (child instanceof t) | ||
result.push(child); | ||
} | ||
return result; | ||
return new Promise((resolve) => { | ||
const result = []; | ||
this.children.forEach((child) => { | ||
if (child instanceof t) { | ||
result.push(child); | ||
} | ||
}); | ||
resolve(result); | ||
}); | ||
} | ||
getAllSymbols(t, localOnly = false) { | ||
let result = new Set(); | ||
for (let child of this._children) { | ||
if (child instanceof t) { | ||
result.add(child); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = []; | ||
for (const child of this.children) { | ||
if (child instanceof t) { | ||
result.push(child); | ||
} | ||
if (child instanceof NamespaceSymbol) { | ||
const childSymbols = yield child.getAllSymbols(t, true); | ||
result.push(...childSymbols); | ||
} | ||
} | ||
if (child instanceof NamespaceSymbol) { | ||
child.getAllSymbols(t, true).forEach(result.add, result); | ||
if (!localOnly) { | ||
if (this.parent instanceof ScopedSymbol) { | ||
const childSymbols = yield this.getAllSymbols(t, true); | ||
result.push(...childSymbols); | ||
} | ||
} | ||
} | ||
if (!localOnly) { | ||
if (this._parent instanceof ScopedSymbol) { | ||
this._parent.getAllSymbols(t, true).forEach(result.add, result); | ||
} | ||
} | ||
return result; | ||
return result; | ||
}); | ||
} | ||
resolve(name, localOnly = false) { | ||
for (let child of this._children) { | ||
if (child.name == name) | ||
return child; | ||
} | ||
if (!localOnly) { | ||
if (this._parent instanceof ScopedSymbol) | ||
return this._parent.resolve(name, false); | ||
} | ||
return undefined; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
for (const child of this.children) { | ||
if (child.name === name) { | ||
resolve(child); | ||
return; | ||
} | ||
} | ||
if (!localOnly) { | ||
if (this.parent instanceof ScopedSymbol) { | ||
resolve(this.parent.resolve(name, false)); | ||
return; | ||
} | ||
} | ||
resolve(undefined); | ||
}); | ||
}); | ||
} | ||
getTypedSymbols(localOnly = true) { | ||
let result = []; | ||
for (let child of this._children) { | ||
const result = []; | ||
for (const child of this.children) { | ||
if (child instanceof TypedSymbol) { | ||
@@ -304,4 +349,4 @@ result.push(child); | ||
if (!localOnly) { | ||
if (this._parent instanceof ScopedSymbol) { | ||
let localList = this._parent.getTypedSymbols(true); | ||
if (this.parent instanceof ScopedSymbol) { | ||
const localList = this.parent.getTypedSymbols(true); | ||
result.push(...localList); | ||
@@ -313,4 +358,4 @@ } | ||
getTypedSymbolNames(localOnly = true) { | ||
let result = []; | ||
for (let child of this._children) { | ||
const result = []; | ||
for (const child of this.children) { | ||
if (child instanceof TypedSymbol) { | ||
@@ -321,4 +366,4 @@ result.push(child.name); | ||
if (!localOnly) { | ||
if (this._parent instanceof ScopedSymbol) { | ||
let localList = this._parent.getTypedSymbolNames(true); | ||
if (this.parent instanceof ScopedSymbol) { | ||
const localList = (this.parent).getTypedSymbolNames(true); | ||
result.push(...localList); | ||
@@ -333,13 +378,16 @@ } | ||
symbolFromPath(path, separator = ".") { | ||
let elements = path.split(separator); | ||
const elements = path.split(separator); | ||
let index = 0; | ||
if (elements[0] == this.name || elements[0].length == 0) | ||
if (elements[0] === this.name || elements[0].length === 0) { | ||
++index; | ||
} | ||
let result = this; | ||
while (index < elements.length) { | ||
if (!(result instanceof ScopedSymbol)) | ||
if (!(result instanceof ScopedSymbol)) { | ||
return undefined; | ||
let child = result._children.find(child => child.name == elements[index]); | ||
if (!child) | ||
} | ||
const child = result.children.find((candidate) => candidate.name === elements[index]); | ||
if (!child) { | ||
return undefined; | ||
} | ||
result = child; | ||
@@ -351,29 +399,29 @@ ++index; | ||
indexOfChild(child) { | ||
return this._children.findIndex((value, index) => { | ||
return value == child; | ||
}); | ||
return this.children.findIndex((value, index) => value === child); | ||
} | ||
nextSiblingOf(child) { | ||
let index = this.indexOfChild(child); | ||
if (index == -1 || index >= this._children.length - 1) { | ||
const index = this.indexOfChild(child); | ||
if (index === -1 || index >= this.children.length - 1) { | ||
return; | ||
} | ||
return this._children[index + 1]; | ||
return this.children[index + 1]; | ||
} | ||
previousSiblingOf(child) { | ||
let index = this.indexOfChild(child); | ||
const index = this.indexOfChild(child); | ||
if (index < 1) { | ||
return; | ||
} | ||
return this._children[index - 1]; | ||
return this.children[index - 1]; | ||
} | ||
get firstChild() { | ||
if (this._children.length > 0) { | ||
return this._children[0]; | ||
if (this.children.length > 0) { | ||
return this.children[0]; | ||
} | ||
return undefined; | ||
} | ||
get lastChild() { | ||
if (this._children.length > 0) { | ||
return this._children[this._children.length - 1]; | ||
if (this.children.length > 0) { | ||
return this.children[this.children.length - 1]; | ||
} | ||
return undefined; | ||
} | ||
@@ -384,3 +432,3 @@ nextOf(child) { | ||
} | ||
if (child.parent != this) { | ||
if (child.parent !== this) { | ||
return child.parent.nextOf(child); | ||
@@ -391,3 +439,3 @@ } | ||
} | ||
let sibling = this.nextSiblingOf(child); | ||
const sibling = this.nextSiblingOf(child); | ||
if (sibling) { | ||
@@ -400,3 +448,2 @@ return sibling; | ||
exports.ScopedSymbol = ScopedSymbol; | ||
; | ||
class NamespaceSymbol extends ScopedSymbol { | ||
@@ -415,3 +462,2 @@ } | ||
exports.VariableSymbol = VariableSymbol; | ||
; | ||
class LiteralSymbol extends TypedSymbol { | ||
@@ -424,7 +470,5 @@ constructor(name, value, type) { | ||
exports.LiteralSymbol = LiteralSymbol; | ||
; | ||
class ParameterSymbol extends VariableSymbol { | ||
} | ||
exports.ParameterSymbol = ParameterSymbol; | ||
; | ||
class RoutineSymbol extends ScopedSymbol { | ||
@@ -443,3 +487,2 @@ constructor(name, returnType) { | ||
exports.RoutineSymbol = RoutineSymbol; | ||
; | ||
var MethodFlags; | ||
@@ -454,6 +497,5 @@ (function (MethodFlags) { | ||
})(MethodFlags = exports.MethodFlags || (exports.MethodFlags = {})); | ||
; | ||
class MethodSymbol extends RoutineSymbol { | ||
constructor(name, returnType) { | ||
super(name, returnType); | ||
constructor() { | ||
super(...arguments); | ||
this.methodFlags = MethodFlags.None; | ||
@@ -464,6 +506,5 @@ this.visibility = MemberVisibility.Invalid; | ||
exports.MethodSymbol = MethodSymbol; | ||
; | ||
class FieldSymbol extends VariableSymbol { | ||
constructor(name, type) { | ||
super(name, type); | ||
constructor() { | ||
super(...arguments); | ||
this.visibility = MemberVisibility.Invalid; | ||
@@ -473,3 +514,2 @@ } | ||
exports.FieldSymbol = FieldSymbol; | ||
; | ||
class ClassSymbol extends ScopedSymbol { | ||
@@ -484,3 +524,2 @@ constructor(name, referenceKind, ...superClass) { | ||
get baseTypes() { return this.superClasses; } | ||
; | ||
get kind() { return TypeKind.Class; } | ||
@@ -496,3 +535,2 @@ get reference() { return this.referenceKind; } | ||
exports.ClassSymbol = ClassSymbol; | ||
; | ||
class ArrayType extends Symbol { | ||
@@ -506,3 +544,2 @@ constructor(name, referenceKind, elemType, size = 0) { | ||
get baseTypes() { return []; } | ||
; | ||
get kind() { return TypeKind.Array; } | ||
@@ -512,3 +549,2 @@ get reference() { return this.referenceKind; } | ||
exports.ArrayType = ArrayType; | ||
; | ||
class SymbolTable extends ScopedSymbol { | ||
@@ -537,8 +573,8 @@ constructor(name, options) { | ||
dependencyCount: this.dependencies.size, | ||
symbolCount: this.children.length | ||
symbolCount: this.children.length, | ||
}; | ||
} | ||
addNewSymbolOfType(t, parent, ...args) { | ||
let result = new t(...args); | ||
if (!parent || parent == this) { | ||
const result = new t(...args); | ||
if (!parent || parent === this) { | ||
this.addSymbol(result); | ||
@@ -552,50 +588,50 @@ } | ||
addNewNamespaceFromPath(parent, path, delimiter = ".") { | ||
let parts = path.split(delimiter); | ||
let i = 0; | ||
let currentParent = (parent == undefined) ? this : parent; | ||
while (i < parts.length - 1) { | ||
let namespace = currentParent.resolve(parts[i], true); | ||
if (namespace == undefined) { | ||
namespace = this.addNewSymbolOfType(NamespaceSymbol, currentParent, parts[i]); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const parts = path.split(delimiter); | ||
let i = 0; | ||
let currentParent = (parent === undefined) ? this : parent; | ||
while (i < parts.length - 1) { | ||
let namespace = yield currentParent.resolve(parts[i], true); | ||
if (namespace === undefined) { | ||
namespace = this.addNewSymbolOfType(NamespaceSymbol, currentParent, parts[i]); | ||
} | ||
currentParent = namespace; | ||
++i; | ||
} | ||
currentParent = namespace; | ||
++i; | ||
} | ||
return this.addNewSymbolOfType(NamespaceSymbol, currentParent, parts[parts.length - 1]); | ||
return this.addNewSymbolOfType(NamespaceSymbol, currentParent, parts[parts.length - 1]); | ||
}); | ||
} | ||
getAllSymbols(t, localOnly = false) { | ||
let type = t ? t : Symbol; | ||
let result = super.getAllSymbols(type, localOnly); | ||
if (!localOnly) { | ||
for (let dependency of this.dependencies) { | ||
dependency.getAllSymbols(t, localOnly).forEach(result.add, result); | ||
getAllSymbols(type, localOnly = false) { | ||
const _super = Object.create(null, { | ||
getAllSymbols: { get: () => super.getAllSymbols } | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield _super.getAllSymbols.call(this, type !== null && type !== void 0 ? type : Symbol, localOnly); | ||
if (!localOnly) { | ||
const dependencyResults = yield Promise.all([...this.dependencies].map((dependency) => (dependency.getAllSymbols(type, localOnly)))); | ||
dependencyResults.forEach((value) => { | ||
result.push(...value); | ||
}); | ||
} | ||
} | ||
return result; | ||
return result; | ||
}); | ||
} | ||
symbolWithContext(context) { | ||
function findRecursive(symbol) { | ||
if (symbol.context == context) { | ||
return symbol; | ||
} | ||
if (symbol instanceof ScopedSymbol) { | ||
for (let child of symbol.children) { | ||
let result = findRecursive(child); | ||
if (result) { | ||
return result; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const findRecursive = (symbol) => { | ||
if (symbol.context === context) { | ||
return symbol; | ||
} | ||
if (symbol instanceof ScopedSymbol) { | ||
for (const child of symbol.children) { | ||
const result = findRecursive(child); | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
let symbols = this.getAllSymbols(Symbol); | ||
for (let symbol of symbols) { | ||
let result = findRecursive(symbol); | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
for (let dependency of this.dependencies) { | ||
symbols = dependency.getAllSymbols(Symbol); | ||
for (let symbol of symbols) { | ||
let result = findRecursive(symbol); | ||
}; | ||
let symbols = yield this.getAllSymbols(Symbol); | ||
for (const symbol of symbols) { | ||
const result = findRecursive(symbol); | ||
if (result) { | ||
@@ -605,18 +641,32 @@ return result; | ||
} | ||
} | ||
for (const dependency of this.dependencies) { | ||
symbols = yield dependency.getAllSymbols(Symbol); | ||
for (const symbol of symbols) { | ||
const result = findRecursive(symbol); | ||
if (result) { | ||
result; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
resolve(name, localOnly = false) { | ||
let result = super.resolve(name, localOnly); | ||
if (!result && !localOnly) { | ||
for (let dependency of this.dependencies) { | ||
result = dependency.resolve(name, false); | ||
if (result) | ||
break; | ||
const _super = Object.create(null, { | ||
resolve: { get: () => super.resolve } | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let result = yield _super.resolve.call(this, name, localOnly); | ||
if (!result && !localOnly) { | ||
for (const dependency of this.dependencies) { | ||
result = yield dependency.resolve(name, false); | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
return result; | ||
}); | ||
} | ||
} | ||
exports.SymbolTable = SymbolTable; | ||
; | ||
//# sourceMappingURL=SymbolTable.js.map |
{ | ||
"name": "antlr4-c3", | ||
"version": "1.1.16", | ||
"version": "2.0.0", | ||
"description": "A code completion core implementation for ANTLR4 based parsers", | ||
@@ -10,3 +10,4 @@ "main": "out/index.js", | ||
"test": "tsc --version && npm run generate && tsc && mocha out/test", | ||
"generate": "antlr4ts test/CPP14.g4 test/Expr.g4 -no-listener -no-visitor" | ||
"generate": "antlr4ts test/CPP14.g4 test/Expr.g4 -no-listener -no-visitor", | ||
"eslint": "eslint ." | ||
}, | ||
@@ -25,13 +26,24 @@ "repository": { | ||
"dependencies": { | ||
"antlr4ts": "^0.5.0-alpha.3" | ||
"antlr4ts": "^0.5.0-alpha.4" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.15", | ||
"@types/mocha": "^8.2.1", | ||
"@types/node": "^14.14.34", | ||
"@types/chai": "^4.2.21", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^16.7.13", | ||
"@typescript-eslint/eslint-plugin": "^4.31.0", | ||
"@typescript-eslint/eslint-plugin-tslint": "^4.31.0", | ||
"@typescript-eslint/parser": "^4.31.0", | ||
"antlr4ts-cli": "^0.5.0-alpha.4", | ||
"chai": "^4.3.3", | ||
"mocha": "^8.3.2", | ||
"chai": "^4.3.4", | ||
"eslint": "^7.32.0", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-jsdoc": "^36.0.8", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"mocha": "^9.1.1", | ||
"path": "^0.12.7", | ||
"typescript": "^3.9.7" | ||
"ts-node": "^10.2.1", | ||
"typescript": "^4.4.2" | ||
}, | ||
@@ -38,0 +50,0 @@ "author": "Mike Lischke", |
[![NPM](https://nodei.co/npm/antlr4-c3.png?downloads=true&downloadRank=true)](https://nodei.co/npm/antlr4-c3/) | ||
[![Build Status](https://travis-ci.org/mike-lischke/antlr4-c3.svg?branch=master)](https://travis-ci.org/mike-lischke/antlr4-c3) | ||
# antlr4-c3 The ANTLR4 Code Completion Core | ||
@@ -88,2 +86,4 @@ | ||
> Since this library is made for ANTLR4 based parser, it requires the same [typescript runtime](https://github.com/tunnelvisionlabs/antlr4ts) as your parser (namely antlr4s). You have to make sure you can actually parse input before continuing with antlr4-c3. | ||
```typescript | ||
@@ -217,2 +217,8 @@ let inputStream = new ANTLRInputStream("var c = a + b()"); | ||
### 2.0.0 | ||
- Breaking change: some of the methods in the symbol table implementation, which may require extra work return now promises (symbol collections and resolver methods). This allows also to override them and return asynchronous results which are constructed from external resources (like database symbols). | ||
### 1.1.16 | ||
- Fixed an issue where wrong tokens were collected for code completion. | ||
### 1.1.15 | ||
@@ -219,0 +225,0 @@ - Fixed a problem with seen states in the follow set determination. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
210391
255
19
1939
Updatedantlr4ts@^0.5.0-alpha.4