Search in sources :

Example 1 with UnknownLanguageException

use of org.graalvm.tools.lsp.exceptions.UnknownLanguageException in project graal by oracle.

the class SourceCodeEvaluator method parse.

public CallTarget parse(final TextDocumentSurrogate surrogate) throws DiagnosticsNotification {
    if (!env.getLanguages().containsKey(surrogate.getLanguageId())) {
        throw new UnknownLanguageException("Unknown language: " + surrogate.getLanguageId() + ". Known languages are: " + env.getLanguages().keySet());
    }
    SourceWrapper sourceWrapper = surrogate.prepareParsing();
    CallTarget callTarget = null;
    try {
        logger.log(Level.FINE, "Parsing {0} {1}", new Object[] { surrogate.getLanguageId(), surrogate.getUri() });
        callTarget = env.parse(sourceWrapper.getSource());
        logger.log(Level.FINER, "Parsing done.");
    } catch (Exception e) {
        if (INTEROP.isException(e)) {
            throw DiagnosticsNotification.create(surrogate.getUri(), Diagnostic.create(SourceUtils.getRangeFrom(e, INTEROP), e.getMessage(), DiagnosticSeverity.Error, null, "Graal", null));
        } else {
            // notification
            throw new RuntimeException(e);
        }
    } finally {
        surrogate.notifyParsingDone(callTarget);
    }
    return callTarget;
}
Also used : SourceWrapper(org.graalvm.tools.lsp.server.utils.SourceWrapper) UnknownLanguageException(org.graalvm.tools.lsp.exceptions.UnknownLanguageException) CallTarget(com.oracle.truffle.api.CallTarget) UnknownLanguageException(org.graalvm.tools.lsp.exceptions.UnknownLanguageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) IOException(java.io.IOException) EvaluationResultException(org.graalvm.tools.lsp.exceptions.EvaluationResultException)

Example 2 with UnknownLanguageException

use of org.graalvm.tools.lsp.exceptions.UnknownLanguageException in project graal by oracle.

the class TruffleAdapter method findLanguageInfo.

/**
 * Special handling needed, because some LSP clients send a MIME type as langId.
 *
 * @param langId an id for a language, e.g. "sl" or "python", or a MIME type
 * @param truffleFile of the concerning file
 * @return a language info
 */
private LanguageInfo findLanguageInfo(final String langId, final TruffleFile truffleFile) {
    Map<String, LanguageInfo> languages = envInternal.getLanguages();
    LanguageInfo langInfo = languages.get(langId);
    if (langInfo != null) {
        return langInfo;
    }
    String possibleMimeType = langId;
    String actualLangId = Source.findLanguage(possibleMimeType);
    if (actualLangId == null) {
        try {
            actualLangId = Source.findLanguage(truffleFile);
        } catch (IOException e) {
        }
        if (actualLangId == null) {
            actualLangId = langId;
        }
    }
    langInfo = languages.get(actualLangId);
    if (langInfo == null) {
        throw new UnknownLanguageException("Unknown language: " + actualLangId + ". Known languages are: " + languages.keySet());
    }
    return langInfo;
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) UnknownLanguageException(org.graalvm.tools.lsp.exceptions.UnknownLanguageException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 UnknownLanguageException (org.graalvm.tools.lsp.exceptions.UnknownLanguageException)2 CallTarget (com.oracle.truffle.api.CallTarget)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 EvaluationResultException (org.graalvm.tools.lsp.exceptions.EvaluationResultException)1 SourceWrapper (org.graalvm.tools.lsp.server.utils.SourceWrapper)1