All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.vespa.schemals.lsp.schema.definition.SchemaDefinition Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
package ai.vespa.schemals.lsp.schema.definition;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.eclipse.lsp4j.Location;

import ai.vespa.schemals.context.EventPositionContext;
import ai.vespa.schemals.index.Symbol;
import ai.vespa.schemals.index.Symbol.SymbolStatus;
import ai.vespa.schemals.index.Symbol.SymbolType;
import ai.vespa.schemals.tree.CSTUtils;
import ai.vespa.schemals.tree.Node;

/**
 * Responsible for LSP textDocument/definition requests.
 */
public class SchemaDefinition {
    public static List getDefinition(EventPositionContext context) {
        ArrayList ret = new ArrayList();

        Node node = CSTUtils.getSymbolAtPosition(context.document.getRootNode(), context.position);

        if (node == null || !node.hasSymbol()) {
            return ret;
        }

        Symbol search = node.getSymbol();

        // Try the faster search first
        Optional results = context.schemaIndex.getNextSymbolDefinition(search);

        if (results.isEmpty() && search.getType() == SymbolType.DOCUMENT) {
            results = context.schemaIndex.findSymbol(search); 
        }

        if (results.isPresent()) {
            ret.add(results.get().getLocation());
        } else if (search.getStatus() == SymbolStatus.DEFINITION) {
            ret.add(search.getLocation());
        }

        return ret;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy