Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Maven editor hints in LSP #3833

Merged
merged 5 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions ide/spi.editor.hints/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.lib</code-name-base>
<code-name-base>org.netbeans.api.lsp</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>3</release-version>
<specification-version>4.0</specification-version>
<release-version>1</release-version>
<specification-version>1.9</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand All @@ -51,6 +51,15 @@
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.lib</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>3</release-version>
<specification-version>4.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -136,27 +145,27 @@
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.ui</code-name-base>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.3</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<code-name-base>org.openide.util.lookup</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.3</specification-version>
<specification-version>8.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.lookup</code-name-base>
<code-name-base>org.openide.util.ui</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.0</specification-version>
<specification-version>9.3</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,10 @@ public synchronized boolean hasErrors() {

return false;
}

public Document getDocument() {
return doc;
}

public synchronized List<ErrorDescription> getErrors() {
return new ArrayList<ErrorDescription>(errors2Lines.keySet());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.editor.hints.lsp;

import java.util.ArrayList;
import java.util.List;
import javax.swing.text.Document;
import org.netbeans.api.editor.document.LineDocument;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.api.lsp.Diagnostic;
import org.netbeans.modules.editor.hints.AnnotationHolder;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.HintsController;
import org.netbeans.spi.lsp.ErrorProvider;
import org.openide.filesystems.FileObject;
import org.openide.text.PositionBounds;

/**
* A simple implementation of {@link ErrorProvider} that converts errors + hints collected by
* {@link HintsController} to LSP {@link Diagnostic}. The implementation <b>does not support</b> code actions yet.
* <p>
* As {@link ErrorProvider}s are registered in MIME Lookup, this implementation is enumerated after those
* possibly registered for specific MIME types.
*
* @author sdedic
*/
@MimeRegistration(mimeType = "", service = ErrorProvider.class)
public class HintsDiagnosticsProvider implements ErrorProvider {
public HintsDiagnosticsProvider() {
}

@Override
public List<? extends Diagnostic> computeErrors(Context context) {
FileObject file = context.file();
AnnotationHolder ah = AnnotationHolder.getInstance(file);
if (ah == null) {
return null;
}
Document doc = ah.getDocument();
if (!(doc instanceof LineDocument)) {
return null;
}
int reportOffset = context.getOffset();
List<Diagnostic> result = new ArrayList<>();
for (ErrorDescription d : ah.getErrors()) {
PositionBounds range = d.getRange();

if (reportOffset > 0 && range.getBegin().getOffset() > reportOffset || range.getEnd().getOffset() <= reportOffset) {
continue;
}

Diagnostic.Builder b = Diagnostic.Builder.create(range.getBegin()::getOffset, range.getEnd()::getOffset, d.getDescription());
b.setCode(d.getId());
Diagnostic.Severity s;

switch (d.getSeverity()) {
case ERROR:
case VERIFIER:
if (context.errorKind() != ErrorProvider.Kind.ERRORS) {
continue;
}
s = Diagnostic.Severity.Error;
break;
case WARNING:
if (context.errorKind() != ErrorProvider.Kind.ERRORS) {
continue;
}
s = Diagnostic.Severity.Warning;
break;
case HINT:
if (context.errorKind() != ErrorProvider.Kind.HINTS) {
continue;
}
s = Diagnostic.Severity.Hint;
break;
default:
// should not happen
s = Diagnostic.Severity.Information;
break;
}

result.add(b.build());
}
return result;
}
}
1 change: 0 additions & 1 deletion java/java.lsp.server/nbcode/nbproject/platform.properties
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ disabled.modules=\
org.netbeans.modules.maven.coverage,\
org.netbeans.modules.maven.grammar,\
org.netbeans.modules.maven.graph,\
org.netbeans.modules.maven.hints,\
org.netbeans.modules.maven.kit,\
org.netbeans.modules.maven.osgi,\
org.netbeans.modules.maven.refactoring,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,11 @@ public void run(ResultIterator resultIterator) throws Exception {
Parser.Result parserResult = resultIterator.getParserResult();
//look for main methods:
List<CodeLens> lens = new ArrayList<>();
if (parserResult == null) {
// no parser for the sourec type
result.complete(lens);
return;
}
CompilationController cc = CompilationController.get(parserResult);
if (cc != null) {
cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
Expand Down
3 changes: 2 additions & 1 deletion java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
{ language: 'java' },
{ language: 'yaml', pattern: '**/{application,bootstrap}*.yml' },
{ language: 'properties', pattern: '**/{application,bootstrap}*.properties' },
{ language: 'jackpot-hint' }
{ language: 'jackpot-hint' },
{ language: 'xml', pattern: '**/pom.xml' }
];
const enableGroovy : boolean = conf.get("netbeans.groovySupport.enabled") || true;
if (enableGroovy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
OpenIDE-Module-Display-Category=Maven
OpenIDE-Module-Name=Maven Editor
OpenIDE-Module-Long-Description=NetBeans Maven integration XML grammar provider, offers code completion for Maven project files etc.
POMResolver=Apache Maven POM Files
Editors/text/x-maven-pom+xml=Apache Maven POM Files
ShowEffPomDiffPanel.lblConfiguration.text=Select &Configuration:
ShowEffPomDiffPanel.rbConfiguration.text=By Configuration
ShowEffPomDiffPanel.rbCustom.text=By Profiles and Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
import org.xml.sax.SAXException;

@Messages("CTL_SourceTabCaption=&Source")
@MIMEResolver.Registration(
displayName="#POMResolver",
position=309,
resource="POMResolver.xml"
)
public class POMDataObject extends MultiDataObject {

public static final String SETTINGS_MIME_TYPE = "text/x-maven-settings+xml";
Expand Down
17 changes: 17 additions & 0 deletions java/maven.hints/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<specification-version>1.11</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.api.lsp</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.9</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.javacapi</code-name-base>
<build-prerequisite/>
Expand All @@ -51,6 +60,14 @@
<specification-version>1.53</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.document</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.25</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.errorstripe.api</code-name-base>
<build-prerequisite/>
Expand Down
Loading