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;
}
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;
}
Aggregations