Search in sources :

Example 1 with DiagnosticsNotification

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

the class CompletionTest method objectPropertyCompletionLocalFile.

@Test
public void objectPropertyCompletionLocalFile() throws InterruptedException, ExecutionException {
    URI uri = createDummyFileUriForSL();
    Future<?> future = truffleAdapter.parse(PROG_OBJ_NOT_CALLED, "sl", uri);
    future.get();
    setTriggerCharacters();
    replace(uri, Range.create(Position.create(2, 12), Position.create(2, 12)), ".", "extraneous input '.'");
    Future<CompletionList> futureC = truffleAdapter.completion(uri, 2, 13, null);
    CompletionList completionList = futureC.get();
    assertEquals(1, completionList.getItems().size());
    CompletionItem item = completionList.getItems().get(0);
    assertEquals("p", item.getLabel());
    assertEquals("Number", item.getDetail());
    assertEquals(CompletionItemKind.Property, item.getKind());
    replace(uri, Range.create(Position.create(2, 12), Position.create(2, 13)), "", null);
    replace(uri, Range.create(Position.create(12, 7), Position.create(12, 7)), ".", "missing IDENTIFIER");
    futureC = truffleAdapter.completion(uri, 12, 8, null);
    try {
        futureC.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof DiagnosticsNotification);
    }
}
Also used : CompletionList(org.graalvm.tools.lsp.server.types.CompletionList) CompletionItem(org.graalvm.tools.lsp.server.types.CompletionItem) DiagnosticsNotification(org.graalvm.tools.lsp.exceptions.DiagnosticsNotification) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.Test)

Example 2 with DiagnosticsNotification

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

the class ParsingTest method parseingWithSyntaxErrors.

@Test
public void parseingWithSyntaxErrors() throws InterruptedException {
    URI uri = createDummyFileUriForSL();
    String text = "function main() {return 3+;}";
    Future<?> future = truffleAdapter.parse(text, "sl", uri);
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        DiagnosticsNotification diagnosticsNotification = getDiagnosticsNotification(e);
        Collection<PublishDiagnosticsParams> diagnosticParamsCollection = diagnosticsNotification.getDiagnosticParamsCollection();
        assertEquals(1, diagnosticParamsCollection.size());
        PublishDiagnosticsParams diagnosticsParams = diagnosticParamsCollection.iterator().next();
        assertEquals(1, diagnosticsParams.getDiagnostics().size());
        assertTrue(rangeCheck(0, 26, 0, 27, diagnosticsParams.getDiagnostics().get(0).getRange()));
    }
}
Also used : PublishDiagnosticsParams(org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams) Collection(java.util.Collection) DiagnosticsNotification(org.graalvm.tools.lsp.exceptions.DiagnosticsNotification) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.Test)

Example 3 with DiagnosticsNotification

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

the class CoverageRequestHandler method runCoverageAnalysisWithEnteredContext.

public Boolean runCoverageAnalysisWithEnteredContext(final URI uri) throws DiagnosticsNotification {
    final TextDocumentSurrogate surrogateOfOpenedFile = surrogateMap.get(uri);
    if (surrogateOfOpenedFile == null) {
        return Boolean.FALSE;
    }
    TextDocumentSurrogate surrogateOfTestFile = sourceCodeEvaluator.createSurrogateForTestFile(surrogateOfOpenedFile, null);
    final URI runScriptUri = surrogateOfTestFile.getUri();
    clearRelatedCoverageData(runScriptUri);
    try {
        final CallTarget callTarget = sourceCodeEvaluator.parse(surrogateOfTestFile);
        LanguageInfo languageInfo = surrogateOfTestFile.getLanguageInfo();
        SourcePredicate predicate = SourcePredicateBuilder.newBuilder().language(languageInfo).excludeInternal(env.getOptions()).build();
        SourceSectionFilter eventFilter = SourceSectionFilter.newBuilder().sourceIs(predicate).build();
        EventBinding<ExecutionEventNodeFactory> eventFactoryBinding = env.getInstrumenter().attachExecutionEventFactory(eventFilter, new ExecutionEventNodeFactory() {

            private final long creatorThreadId = Thread.currentThread().getId();

            @Override
            public ExecutionEventNode create(final EventContext eventContext) {
                final SourceSection section = eventContext.getInstrumentedSourceSection();
                if (section != null && section.isAvailable()) {
                    final Node instrumentedNode = eventContext.getInstrumentedNode();
                    Function<URI, TextDocumentSurrogate> func = (sourceUri) -> {
                        return surrogateMap.getOrCreateSurrogate(sourceUri, () -> instrumentedNode.getRootNode().getLanguageInfo());
                    };
                    return new CoverageEventNode(section, instrumentedNode, runScriptUri, func, creatorThreadId);
                } else {
                    return null;
                }
            }
        });
        try {
            callTarget.call();
        } finally {
            eventFactoryBinding.dispose();
        }
        surrogateOfOpenedFile.setCoverageAnalysisDone(true);
        return Boolean.TRUE;
    } catch (DiagnosticsNotification e) {
        throw e;
    } catch (Exception e) {
        InteropLibrary interopLib = InteropLibrary.getUncached();
        if (interopLib.isException(e)) {
            SourceSection sourceSection;
            try {
                sourceSection = interopLib.hasSourceLocation(e) ? interopLib.getSourceLocation(e) : null;
            } catch (UnsupportedMessageException um) {
                throw CompilerDirectives.shouldNotReachHere(um);
            }
            URI uriOfErronousSource = sourceSection != null ? sourceSection.getSource().getURI() : null;
            if (uriOfErronousSource == null) {
                uriOfErronousSource = uri;
            }
            throw DiagnosticsNotification.create(uriOfErronousSource, Diagnostic.create(SourceUtils.getRangeFrom(e, interopLib), e.getMessage(), DiagnosticSeverity.Error, null, "Coverage analysis", null));
        }
        throw e;
    }
}
Also used : ExecutionEventNodeFactory(com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory) CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) CoverageEventNode(org.graalvm.tools.lsp.server.utils.CoverageEventNode) TextDocumentSurrogate(org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) DiagnosticsNotification(org.graalvm.tools.lsp.exceptions.DiagnosticsNotification) URI(java.net.URI) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) EventContext(com.oracle.truffle.api.instrumentation.EventContext) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) Function(java.util.function.Function) SourcePredicate(com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) CoverageEventNode(org.graalvm.tools.lsp.server.utils.CoverageEventNode) SourceSection(com.oracle.truffle.api.source.SourceSection) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode)

Aggregations

URI (java.net.URI)3 DiagnosticsNotification (org.graalvm.tools.lsp.exceptions.DiagnosticsNotification)3 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 CallTarget (com.oracle.truffle.api.CallTarget)1 EventContext (com.oracle.truffle.api.instrumentation.EventContext)1 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)1 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)1 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)1 SourcePredicate (com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate)1 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 Node (com.oracle.truffle.api.nodes.Node)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 Collection (java.util.Collection)1 Function (java.util.function.Function)1 CompletionItem (org.graalvm.tools.lsp.server.types.CompletionItem)1 CompletionList (org.graalvm.tools.lsp.server.types.CompletionList)1 PublishDiagnosticsParams (org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams)1