完成世界书、骰子、apiconfig页面处理
This commit is contained in:
1
frontend/node_modules/langium/lib/grammar/references/grammar-naming.js.map
generated
vendored
Normal file
1
frontend/node_modules/langium/lib/grammar/references/grammar-naming.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"grammar-naming.js","sourceRoot":"","sources":["../../../src/grammar/references/grammar-naming.ts"],"names":[],"mappings":"AAAA;;;;+EAI+E;AAG/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,MAAM,OAAO,0BAA2B,SAAQ,mBAAmB;IAEtD,OAAO,CAAC,IAAa;QAC1B,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,OAAO,CAAC;QACxB,CAAC;aAAM,CAAC;YACJ,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC;IAEQ,WAAW,CAAC,IAAa;QAC9B,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACJ,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;CAEJ"}
|
||||
180
frontend/node_modules/langium/lib/grammar/references/grammar-references.js
generated
vendored
Normal file
180
frontend/node_modules/langium/lib/grammar/references/grammar-references.js
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2021 TypeFox GmbH
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License, which is available in the project root.
|
||||
******************************************************************************/
|
||||
import { DefaultReferences } from '../../references/references.js';
|
||||
import { getContainerOfType, getDocument } from '../../utils/ast-utils.js';
|
||||
import { toDocumentSegment } from '../../utils/cst-utils.js';
|
||||
import { findAssignment, findNodeForKeyword, findNodeForProperty, getActionAtElement } from '../../utils/grammar-utils.js';
|
||||
import { stream } from '../../utils/stream.js';
|
||||
import { UriUtils } from '../../utils/uri-utils.js';
|
||||
import { isAbstractParserRule, isAction, isAssignment, isInfixRule, isInterface, isParserRule, isType, isTypeAttribute } from '../../languages/generated/ast.js';
|
||||
import { extractAssignments } from '../internal-grammar-util.js';
|
||||
import { collectChildrenTypes, collectSuperTypes } from '../type-system/types-util.js';
|
||||
import { assertUnreachable } from '../../utils/errors.js';
|
||||
export class LangiumGrammarReferences extends DefaultReferences {
|
||||
findDeclarations(sourceCstNode) {
|
||||
const nodeElem = sourceCstNode.astNode;
|
||||
const assignment = findAssignment(sourceCstNode);
|
||||
if (assignment && assignment.feature === 'feature') {
|
||||
// Only search for a special declaration if the cst node is the feature property of the action/assignment
|
||||
if (isAssignment(nodeElem)) {
|
||||
const decl = this.findAssignmentDeclaration(nodeElem);
|
||||
return decl ? [decl] : [];
|
||||
}
|
||||
else if (isAction(nodeElem)) {
|
||||
const decl = this.findActionDeclaration(nodeElem);
|
||||
return decl ? [decl] : [];
|
||||
}
|
||||
}
|
||||
return super.findDeclarations(sourceCstNode);
|
||||
}
|
||||
findReferences(targetNode, options) {
|
||||
if (isTypeAttribute(targetNode)) {
|
||||
return this.findReferencesToTypeAttribute(targetNode, options.includeDeclaration ?? false);
|
||||
}
|
||||
else {
|
||||
return super.findReferences(targetNode, options);
|
||||
}
|
||||
}
|
||||
findReferencesToTypeAttribute(targetNode, includeDeclaration) {
|
||||
const refs = [];
|
||||
const interfaceNode = getContainerOfType(targetNode, isInterface);
|
||||
if (interfaceNode) {
|
||||
if (includeDeclaration) {
|
||||
refs.push(...this.getSelfReferences(targetNode));
|
||||
}
|
||||
const interfaces = collectChildrenTypes(interfaceNode, this, this.documents, this.nodeLocator);
|
||||
const targetRules = [];
|
||||
interfaces.forEach(interf => {
|
||||
const rules = this.findRulesWithReturnType(interf);
|
||||
targetRules.push(...rules);
|
||||
});
|
||||
targetRules.forEach(rule => {
|
||||
const references = this.createReferencesToAttribute(rule, targetNode);
|
||||
refs.push(...references);
|
||||
});
|
||||
}
|
||||
return stream(refs);
|
||||
}
|
||||
createReferencesToAttribute(ruleOrAction, attribute) {
|
||||
const refs = [];
|
||||
if (isParserRule(ruleOrAction)) {
|
||||
const assignment = extractAssignments(ruleOrAction.definition).find(a => a.feature === attribute.name);
|
||||
if (assignment?.$cstNode) {
|
||||
const leaf = this.nameProvider.getNameNode(assignment);
|
||||
if (leaf) {
|
||||
const assignmentUri = getDocument(assignment).uri;
|
||||
const attributeUri = getDocument(attribute).uri;
|
||||
refs.push({
|
||||
sourceUri: assignmentUri,
|
||||
sourcePath: this.nodeLocator.getAstNodePath(assignment),
|
||||
targetUri: attributeUri,
|
||||
targetPath: this.nodeLocator.getAstNodePath(attribute),
|
||||
segment: toDocumentSegment(leaf),
|
||||
local: UriUtils.equals(assignmentUri, attributeUri)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isInfixRule(ruleOrAction)) {
|
||||
let leaf;
|
||||
if (attribute.name === 'left' || attribute.name === 'right') {
|
||||
// Use the 'on' keyword as segment
|
||||
leaf = findNodeForKeyword(ruleOrAction.$cstNode, 'on');
|
||||
}
|
||||
else if (attribute.name === 'operator') {
|
||||
// Use the rule definition in 'operators' as segment
|
||||
leaf = findNodeForProperty(ruleOrAction.$cstNode, 'operators');
|
||||
}
|
||||
if (leaf) {
|
||||
const ruleUri = getDocument(ruleOrAction).uri;
|
||||
const attributeUri = getDocument(attribute).uri;
|
||||
refs.push({
|
||||
sourceUri: ruleUri,
|
||||
sourcePath: this.nodeLocator.getAstNodePath(ruleOrAction),
|
||||
targetUri: attributeUri,
|
||||
targetPath: this.nodeLocator.getAstNodePath(attribute),
|
||||
segment: toDocumentSegment(leaf),
|
||||
local: UriUtils.equals(ruleUri, attributeUri)
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (isAction(ruleOrAction)) {
|
||||
// If the action references the attribute directly
|
||||
if (ruleOrAction.feature === attribute.name) {
|
||||
const leaf = findNodeForProperty(ruleOrAction.$cstNode, 'feature');
|
||||
if (leaf) {
|
||||
const actionUri = getDocument(ruleOrAction).uri;
|
||||
const attributeUri = getDocument(attribute).uri;
|
||||
refs.push({
|
||||
sourceUri: actionUri,
|
||||
sourcePath: this.nodeLocator.getAstNodePath(ruleOrAction),
|
||||
targetUri: attributeUri,
|
||||
targetPath: this.nodeLocator.getAstNodePath(attribute),
|
||||
segment: toDocumentSegment(leaf),
|
||||
local: UriUtils.equals(actionUri, attributeUri)
|
||||
});
|
||||
}
|
||||
}
|
||||
// Find all references within the parser rule that contains this action
|
||||
const parserRule = getContainerOfType(ruleOrAction, isParserRule);
|
||||
refs.push(...this.createReferencesToAttribute(parserRule, attribute));
|
||||
}
|
||||
else {
|
||||
assertUnreachable(ruleOrAction);
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
findAssignmentDeclaration(assignment) {
|
||||
const parserRule = getContainerOfType(assignment, isParserRule);
|
||||
const action = getActionAtElement(assignment);
|
||||
if (action) {
|
||||
const actionDeclaration = this.findActionDeclaration(action, assignment.feature);
|
||||
if (actionDeclaration) {
|
||||
return actionDeclaration;
|
||||
}
|
||||
}
|
||||
if (parserRule?.returnType?.ref) {
|
||||
if (isInterface(parserRule.returnType.ref) || isType(parserRule.returnType.ref)) {
|
||||
const interfaces = collectSuperTypes(parserRule.returnType.ref);
|
||||
for (const interf of interfaces) {
|
||||
const typeAttribute = interf.attributes.find(att => att.name === assignment.feature);
|
||||
if (typeAttribute) {
|
||||
return typeAttribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return assignment;
|
||||
}
|
||||
findActionDeclaration(action, featureName) {
|
||||
if (action.type?.ref) {
|
||||
const feature = featureName ?? action.feature;
|
||||
const interfaces = collectSuperTypes(action.type.ref);
|
||||
for (const interf of interfaces) {
|
||||
const typeAttribute = interf.attributes.find(att => att.name === feature);
|
||||
if (typeAttribute) {
|
||||
return typeAttribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
findRulesWithReturnType(interf) {
|
||||
const rules = [];
|
||||
const refs = this.index.findAllReferences(interf, this.nodeLocator.getAstNodePath(interf));
|
||||
for (const ref of refs) {
|
||||
const doc = this.documents.getDocument(ref.sourceUri);
|
||||
if (doc) {
|
||||
const astNode = this.nodeLocator.getAstNode(doc.parseResult.value, ref.sourcePath);
|
||||
if (isAbstractParserRule(astNode) || isAction(astNode)) {
|
||||
rules.push(astNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=grammar-references.js.map
|
||||
164
frontend/node_modules/langium/lib/grammar/references/grammar-scope.js
generated
vendored
Normal file
164
frontend/node_modules/langium/lib/grammar/references/grammar-scope.js
generated
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2021 TypeFox GmbH
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License, which is available in the project root.
|
||||
******************************************************************************/
|
||||
import { EMPTY_SCOPE, MultiMapScope } from '../../references/scope.js';
|
||||
import { DefaultScopeComputation } from '../../references/scope-computation.js';
|
||||
import { DefaultScopeProvider } from '../../references/scope-provider.js';
|
||||
import { findRootNode, getContainerOfType, getDocument, streamAllContents } from '../../utils/ast-utils.js';
|
||||
import { toDocumentSegment } from '../../utils/cst-utils.js';
|
||||
import { AbstractType, InferredType, Interface, NamedArgument, Type, isAbstractParserRule, isAction, isGrammar, isReturnType, isRuleCall } from '../../languages/generated/ast.js';
|
||||
import { resolveImportUri } from '../internal-grammar-util.js';
|
||||
export class LangiumGrammarScopeProvider extends DefaultScopeProvider {
|
||||
constructor(services) {
|
||||
super(services);
|
||||
this.langiumDocuments = services.shared.workspace.LangiumDocuments;
|
||||
}
|
||||
getScope(context) {
|
||||
if (context.container.$type === NamedArgument.$type && context.property === 'parameter') {
|
||||
return this.getNamedArgumentScope(context);
|
||||
}
|
||||
const referenceType = this.reflection.getReferenceType(context);
|
||||
if (referenceType === AbstractType.$type) {
|
||||
return this.getTypeScope(referenceType, context);
|
||||
}
|
||||
else {
|
||||
return super.getScope(context);
|
||||
}
|
||||
}
|
||||
getNamedArgumentScope(context) {
|
||||
const ruleCall = context.container.$container;
|
||||
if (!isRuleCall(ruleCall)) {
|
||||
return EMPTY_SCOPE;
|
||||
}
|
||||
const rule = ruleCall.rule.ref;
|
||||
if (!isAbstractParserRule(rule)) {
|
||||
return EMPTY_SCOPE;
|
||||
}
|
||||
return this.createScopeForNodes(rule.parameters);
|
||||
}
|
||||
getTypeScope(referenceType, context) {
|
||||
const localSymbols = getDocument(context.container).localSymbols;
|
||||
const rootNode = findRootNode(context.container);
|
||||
if (localSymbols && rootNode && localSymbols.has(rootNode)) {
|
||||
const globalScope = this.getGlobalScope(referenceType, context);
|
||||
const localScope = localSymbols.getStream(rootNode).filter(des => des.type === Interface.$type || des.type === Type.$type || des.type === InferredType.$type);
|
||||
return this.createScope(localScope, globalScope);
|
||||
}
|
||||
else {
|
||||
return this.getGlobalScope(referenceType, context);
|
||||
}
|
||||
}
|
||||
getGlobalScope(referenceType, context) {
|
||||
const grammar = getContainerOfType(context.container, isGrammar);
|
||||
if (!grammar) {
|
||||
return EMPTY_SCOPE;
|
||||
}
|
||||
const importedUris = new Set();
|
||||
this.gatherImports(grammar, importedUris);
|
||||
let importedElements = this.indexManager.allElements(referenceType, importedUris);
|
||||
if (referenceType === AbstractType.$type) {
|
||||
importedElements = importedElements.filter(des => des.type === Interface.$type || des.type === Type.$type || des.type === InferredType.$type);
|
||||
}
|
||||
return new MultiMapScope(importedElements);
|
||||
}
|
||||
gatherImports(grammar, importedUris) {
|
||||
for (const imp0rt of grammar.imports) {
|
||||
const uri = resolveImportUri(imp0rt);
|
||||
if (uri && !importedUris.has(uri.toString())) {
|
||||
importedUris.add(uri.toString());
|
||||
const importedDocument = this.langiumDocuments.getDocument(uri);
|
||||
if (importedDocument) {
|
||||
const rootNode = importedDocument.parseResult.value;
|
||||
if (isGrammar(rootNode)) {
|
||||
this.gatherImports(rootNode, importedUris);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export class LangiumGrammarScopeComputation extends DefaultScopeComputation {
|
||||
constructor(services) {
|
||||
super(services);
|
||||
this.astNodeLocator = services.workspace.AstNodeLocator;
|
||||
}
|
||||
addExportedSymbol(node, exports, document) {
|
||||
// this function is called in order to export nodes to the GLOBAL scope
|
||||
/* Among others, TYPES need to be exported.
|
||||
* There are three ways to define types:
|
||||
* - explicit "type" declarations
|
||||
* - explicit "interface" declarations
|
||||
* - "inferred types", which can be distinguished into ...
|
||||
* - inferred types with explicitly declared names, i.e. parser rules with "infers", actions with "infer"
|
||||
* Note, that multiple explicitly inferred types might have the same name! Cross-references to such types are resolved to the first declaration.
|
||||
* - implicitly inferred types, i.e. parser rules without "infers" and without "returns",
|
||||
* which implicitly declare a type with the same name as the parser rule
|
||||
* Note, that implicitly inferred types are unique, since names of parser rules must be unique.
|
||||
*/
|
||||
// export the top-level elements: parser rules, terminal rules, types, interfaces
|
||||
super.addExportedSymbol(node, exports, document);
|
||||
// additionally, export inferred types:
|
||||
if (isAbstractParserRule(node)) {
|
||||
if (!node.returnType && !node.dataType) {
|
||||
// Export implicitly and explicitly inferred type from parser rule
|
||||
const typeNode = node.inferredType ?? node;
|
||||
exports.push(this.createInferredTypeDescription(typeNode, typeNode.name, document));
|
||||
}
|
||||
streamAllContents(node).forEach(childNode => {
|
||||
if (isAction(childNode) && childNode.inferredType) {
|
||||
// Export explicitly inferred type from action
|
||||
exports.push(this.createInferredTypeDescription(childNode.inferredType, childNode.inferredType.name, document));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
addLocalSymbol(node, document, symbols) {
|
||||
// for the precompution of the local scope
|
||||
if (isReturnType(node)) {
|
||||
return;
|
||||
}
|
||||
this.processTypeNode(node, document, symbols);
|
||||
this.processActionNode(node, document, symbols);
|
||||
super.addLocalSymbol(node, document, symbols);
|
||||
}
|
||||
/**
|
||||
* Add synthetic type into the scope in case of explicitly or implicitly inferred type:<br>
|
||||
* cases: `ParserRule: ...;` or `ParserRule infers Type: ...;`
|
||||
*/
|
||||
processTypeNode(node, document, symbols) {
|
||||
const container = node.$container;
|
||||
if (container && isAbstractParserRule(node) && !node.returnType && !node.dataType) {
|
||||
const typeNode = node.inferredType ?? node;
|
||||
symbols.add(container, this.createInferredTypeDescription(typeNode, typeNode.name, document));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add synthetic type into the scope in case of explicitly inferred type:
|
||||
*
|
||||
* case: `{infer Action}`
|
||||
*/
|
||||
processActionNode(node, document, symbols) {
|
||||
const container = findRootNode(node);
|
||||
if (container && isAction(node) && node.inferredType) {
|
||||
symbols.add(container, this.createInferredTypeDescription(node.inferredType, node.inferredType.name, document));
|
||||
}
|
||||
}
|
||||
createInferredTypeDescription(node, name, document = getDocument(node)) {
|
||||
let nameNodeSegment;
|
||||
const nameSegmentGetter = () => nameNodeSegment ?? (nameNodeSegment = toDocumentSegment(this.nameProvider.getNameNode(node) ?? node.$cstNode));
|
||||
return {
|
||||
node,
|
||||
name,
|
||||
get nameSegment() {
|
||||
return nameSegmentGetter();
|
||||
},
|
||||
selectionSegment: toDocumentSegment(node.$cstNode),
|
||||
type: InferredType.$type,
|
||||
documentUri: document.uri,
|
||||
path: this.astNodeLocator.getAstNodePath(node)
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=grammar-scope.js.map
|
||||
Reference in New Issue
Block a user