Search in sources :

Example 1 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method getProject.

private FlexProject getProject() {
    clearInvisibleCompilationUnits();
    refreshProjectOptions();
    if (currentProjectOptions == null) {
        cleanupCurrentProject();
        return null;
    }
    FlexProject project = null;
    if (currentProject == null) {
        project = new FlexProject(new Workspace());
        project.setProblems(new ArrayList<>());
        currentWorkspace = project.getWorkspace();
        fileSpecGetter = new LanguageServerFileSpecGetter(currentWorkspace, sourceByPath);
    } else {
        //clear all old problems because they won't be cleared automatically
        currentProject.getProblems().clear();
        return currentProject;
    }
    CompilerOptions compilerOptions = currentProjectOptions.compilerOptions;
    Configurator configurator = null;
    if (isJSConfig(currentProjectOptions)) {
        configurator = new Configurator(JSGoogConfiguration.class);
    } else //swf only
    {
        configurator = new Configurator(Configuration.class);
    }
    configurator.setToken(TOKEN_CONFIGNAME, currentProjectOptions.config);
    ProjectType type = currentProjectOptions.type;
    String[] files = currentProjectOptions.files;
    String additionalOptions = currentProjectOptions.additionalOptions;
    ArrayList<String> combinedOptions = new ArrayList<>();
    if (compilerOptions.swfExternalLibraryPath != null) {
        //this isn't available in the configurator, so add it like the additionalOptions
        appendPathCompilerOptions("--swf-external-library-path+=", compilerOptions.swfExternalLibraryPath, combinedOptions);
    }
    if (compilerOptions.swfLibraryPath != null) {
        appendPathCompilerOptions("--swf-library-path+=", compilerOptions.swfLibraryPath, combinedOptions);
    }
    if (compilerOptions.jsExternalLibraryPath != null) {
        appendPathCompilerOptions("--js-external-library-path+=", compilerOptions.jsExternalLibraryPath, combinedOptions);
    }
    if (compilerOptions.jsLibraryPath != null) {
        appendPathCompilerOptions("--js-library-path+=", compilerOptions.jsLibraryPath, combinedOptions);
    }
    if (additionalOptions != null) {
        //split the additionalOptions into separate values so that we can
        //pass them in as String[], as the compiler expects.
        Matcher matcher = additionalOptionsPattern.matcher(additionalOptions);
        while (matcher.find()) {
            String option = matcher.group();
            combinedOptions.add(option);
        }
    }
    //not all framework SDKs support a theme (such as Adobe's AIR SDK), so
    //we clear it for the editor to avoid a missing spark.css file.
    combinedOptions.add("-theme=");
    if (type.equals(ProjectType.LIB)) {
        configurator.setConfiguration(combinedOptions.toArray(new String[combinedOptions.size()]), ICompilerSettingsConstants.INCLUDE_CLASSES_VAR, false);
    } else // app
    {
        combinedOptions.addAll(Arrays.asList(files));
        configurator.setConfiguration(combinedOptions.toArray(new String[combinedOptions.size()]), ICompilerSettingsConstants.FILE_SPECS_VAR);
    }
    //this needs to be set before applyToProject() so that it's in the
    //configuration buffer before addExternalLibraryPath() is called
    configurator.setExcludeNativeJSLibraries(false);
    boolean result = configurator.applyToProject(project);
    Collection<ICompilerProblem> problems = configurator.getConfigurationProblems();
    if (problems.size() > 0) {
        Map<URI, PublishDiagnosticsParams> filesMap = new HashMap<>();
        for (ICompilerProblem problem : problems) {
            URI uri = Paths.get(problem.getSourcePath()).toUri();
            configProblemTracker.trackFileWithProblems(uri);
            PublishDiagnosticsParams params = null;
            if (filesMap.containsKey(uri)) {
                params = filesMap.get(uri);
            } else {
                params = new PublishDiagnosticsParams();
                params.setUri(uri.toString());
                params.setDiagnostics(new ArrayList<>());
                filesMap.put(uri, params);
            }
            addCompilerProblem(problem, params);
        }
        if (languageClient != null) {
            filesMap.values().forEach(languageClient::publishDiagnostics);
        }
    //we don't return null if result is not false
    }
    configProblemTracker.cleanUpStaleProblems();
    if (!result) {
        return null;
    }
    //because setting some values checks the cfgbuf
    if (compilerOptions.sourcePath != null) {
        configurator.addSourcePath(compilerOptions.sourcePath);
    }
    if (compilerOptions.libraryPath != null) {
        configurator.addLibraryPath(compilerOptions.libraryPath);
    }
    if (compilerOptions.externalLibraryPath != null) {
        configurator.addExternalLibraryPath(compilerOptions.externalLibraryPath);
    }
    if (compilerOptions.namespaceMappings != null) {
        configurator.setNamespaceMappings(compilerOptions.namespaceMappings);
    }
    if (compilerOptions.defines != null) {
        configurator.setDefineDirectives(compilerOptions.defines);
    }
    if (currentProjectOptions.type.equals(ProjectType.LIB)) {
        if (compilerOptions.includeClasses != null) {
            configurator.setIncludeClasses(compilerOptions.includeClasses);
        }
        if (compilerOptions.includeNamespaces != null) {
            configurator.setIncludeNamespaces(compilerOptions.includeNamespaces);
        }
        if (compilerOptions.includeSources != null) {
            configurator.setIncludeSources(compilerOptions.includeSources);
        }
    }
    configurator.enableDebugging(compilerOptions.debug, null);
    configurator.showActionScriptWarnings(compilerOptions.warnings);
    result = configurator.applyToProject(project);
    if (!result) {
        return null;
    }
    ITarget.TargetType targetType = ITarget.TargetType.SWF;
    if (currentProjectOptions.type.equals(ProjectType.LIB)) {
        targetType = ITarget.TargetType.SWC;
    }
    ITargetSettings targetSettings = configurator.getTargetSettings(targetType);
    if (targetSettings == null) {
        System.err.println("Failed to get compile settings for +configname=" + currentProjectOptions.config + ".");
        return null;
    }
    project.setTargetSettings(targetSettings);
    return project;
}
Also used : JSGoogConfiguration(org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration) Configuration(org.apache.flex.compiler.config.Configuration) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Configurator(org.apache.flex.compiler.config.Configurator) ArrayList(java.util.ArrayList) ITargetSettings(org.apache.flex.compiler.targets.ITargetSettings) URI(java.net.URI) JSGoogConfiguration(org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration) FlexProject(org.apache.flex.compiler.internal.projects.FlexProject) ITarget(org.apache.flex.compiler.targets.ITarget) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) ProjectType(com.nextgenactionscript.vscode.project.ProjectType) CompilerOptions(com.nextgenactionscript.vscode.project.CompilerOptions) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Workspace(org.apache.flex.compiler.internal.workspaces.Workspace) IWorkspace(org.apache.flex.compiler.workspaces.IWorkspace)

Example 2 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project vscode-nextgenas by BowlerHatLLC.

the class ProblemTracker method cleanUpStaleProblems.

public void cleanUpStaleProblems() {
    //clear the errors so that they don't persist
    for (URI uri : oldFilesWithProblems) {
        PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
        publish.setDiagnostics(new ArrayList<>());
        publish.setUri(uri.toString());
        if (languageClient != null) {
            languageClient.publishDiagnostics(publish);
        }
    }
    oldFilesWithProblems.clear();
    HashSet<URI> temp = newFilesWithProblems;
    newFilesWithProblems = oldFilesWithProblems;
    oldFilesWithProblems = temp;
}
Also used : PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) URI(java.net.URI)

Example 3 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project sonarlint-core by SonarSource.

the class SonarLintLanguageServer method analyze.

private void analyze(URI uri, String content) {
    Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
    files.put(uri, newPublishDiagnostics(uri));
    Path baseDir = workspaceRoot != null ? Paths.get(workspaceRoot) : Paths.get(uri).getParent();
    Objects.requireNonNull(baseDir);
    Objects.requireNonNull(engine);
    StandaloneAnalysisConfiguration configuration = new StandaloneAnalysisConfiguration(baseDir, baseDir.resolve(".sonarlint"), Arrays.asList(new DefaultClientInputFile(baseDir, uri, content, userSettings.testFilePattern, languageIdPerFileURI.get(uri))), userSettings.analyzerProperties);
    debug("Analysis triggered on " + uri + " with configuration: \n" + configuration.toString());
    long start = System.currentTimeMillis();
    AnalysisResults analysisResults = engine.analyze(configuration, issue -> {
        ClientInputFile inputFile = issue.getInputFile();
        if (inputFile != null) {
            URI uri1 = inputFile.getClientObject();
            PublishDiagnosticsParams publish = files.computeIfAbsent(uri1, SonarLintLanguageServer::newPublishDiagnostics);
            convert(issue).ifPresent(publish.getDiagnostics()::add);
        }
    }, logOutput, null);
    telemetry.analysisDoneOnSingleFile(StringUtils.substringAfterLast(uri.toString(), "."), (int) (System.currentTimeMillis() - start));
    // Ignore files with parsing error
    analysisResults.failedAnalysisFiles().stream().map(ClientInputFile::getClientObject).forEach(files::remove);
    files.values().forEach(client::publishDiagnostics);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) URI(java.net.URI) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 4 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.

the class BuildWorkspaceHandler method publishDiagnostics.

private void publishDiagnostics(List<IMarker> markers) {
    Map<IResource, List<IMarker>> map = markers.stream().collect(Collectors.groupingBy(IMarker::getResource));
    for (Map.Entry<IResource, List<IMarker>> entry : map.entrySet()) {
        IResource resource = entry.getKey();
        // ignore problems caused by standalone files
        if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject())) {
            continue;
        }
        IFile file = resource.getAdapter(IFile.class);
        if (file == null) {
            continue;
        }
        IDocument document = null;
        String uri = JDTUtils.getFileURI(resource);
        if (JavaCore.isJavaLikeFileName(file.getName())) {
            ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
            try {
                document = JsonRpcHelpers.toDocument(cu.getBuffer());
            } catch (JavaModelException e) {
                logException("Failed to publish diagnostics.", e);
            }
        } else if (projectsManager.isBuildFile(file)) {
            document = JsonRpcHelpers.toDocument(file);
        }
        if (document != null) {
            List<Diagnostic> diagnostics = WorkspaceDiagnosticsHandler.toDiagnosticsArray(document, entry.getValue().toArray(new IMarker[0]));
            connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) Diagnostic(org.eclipse.lsp4j.Diagnostic) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ArrayList(java.util.ArrayList) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.

the class DiagnosticsHandler method clearDiagnostics.

public void clearDiagnostics() {
    JavaLanguageServerPlugin.logInfo("Clearing problems for " + this.uri.substring(this.uri.lastIndexOf('/')));
    problems.clear();
    PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList());
    this.connection.publishDiagnostics($);
}
Also used : PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Aggregations

PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)22 Diagnostic (org.eclipse.lsp4j.Diagnostic)8 URI (java.net.URI)7 ArrayList (java.util.ArrayList)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 HashMap (java.util.HashMap)4 ICompilerProblem (org.apache.flex.compiler.problems.ICompilerProblem)4 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ConcurrentModificationException (java.util.ConcurrentModificationException)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)3 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2 Workspace (org.apache.flex.compiler.internal.workspaces.Workspace)2 IWorkspace (org.apache.flex.compiler.workspaces.IWorkspace)2