Search in sources :

Example 1 with TsLintLanguageService

use of com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService in project intellij-plugins by JetBrains.

the class TsLintFileFixAction method createTask.

@Override
protected Task createTask(@NotNull Project project, @NotNull Collection<VirtualFile> filesToProcess, @NotNull Runnable completeCallback) {
    LocalHistory.getInstance().putSystemLabel(project, JSBundle.message("javascript.linter.action.fix.problems.name.start", TsLintBundle.message("tslint.framework.title")));
    return new Task.Backgroundable(project, TsLintBundle.message("tslint.action.background.title"), true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            TsLintLanguageService service = TsLintLanguageService.getService(project);
            TsLintState state = TsLintConfiguration.getInstance(project).getExtendedState().getState();
            for (VirtualFile file : filesToProcess) {
                indicator.setText("Processing file " + file.getCanonicalPath());
                Future<List<TsLinterError>> future = ReadAction.compute(() -> service.highlightAndFix(file, state));
                JSLanguageServiceUtil.awaitFuture(future, JSLanguageServiceUtil.TIMEOUT_MILLS, JSLanguageServiceUtil.QUOTA_MILLS, indicator);
            }
            completeCallback.run();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TsLintState(com.intellij.lang.javascript.linter.tslint.config.TsLintState) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TsLintLanguageService(com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TsLintLanguageService

use of com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService in project intellij-plugins by JetBrains.

the class TsLintExternalAnnotator method annotate.

@Nullable
@Override
public JSLinterAnnotationResult<TsLintState> annotate(@NotNull TsLinterInput collectedInfo) {
    TsLintLanguageService service = TsLintLanguageService.getService(collectedInfo.getProject());
    VirtualFile config = collectedInfo.getConfig();
    Future<List<TsLinterError>> highlight = service.highlight(collectedInfo.getVirtualFile(), config, collectedInfo.getFileContent());
    List<TsLinterError> annotationErrors = JSLanguageServiceUtil.awaitFuture(highlight);
    if (annotationErrors == null) {
        if (!service.isServiceCreated() || service.getServiceCreationError() != null) {
            String error = service.getServiceCreationError();
            error = error == null ? JSLanguageServiceQueueImpl.CANNOT_START_LANGUAGE_SERVICE_PROCESS : error;
            return JSLinterAnnotationResult.create(collectedInfo, new JSLinterFileLevelAnnotation(error), config);
        }
        return null;
    }
    if (!annotationErrors.isEmpty()) {
        final Optional<TsLinterError> globalError = annotationErrors.stream().filter(error -> error.isGlobal()).findFirst();
        if (globalError.isPresent()) {
            final JSLinterAnnotationResult<TsLintState> annotation = createGlobalErrorMessage(collectedInfo, config, globalError.get().getDescription());
            if (annotation != null)
                return annotation;
        }
    }
    List<JSLinterError> result = filterResultByFile(collectedInfo, annotationErrors);
    return JSLinterAnnotationResult.createLinterResult(collectedInfo, result, config);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) AnnotationHolder(com.intellij.lang.annotation.AnnotationHolder) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DialectDetector(com.intellij.lang.javascript.DialectDetector) DialectOptionHolder(com.intellij.lang.javascript.DialectOptionHolder) TsLintBundle(com.intellij.lang.javascript.linter.tslint.TsLintBundle) JSUtils(com.intellij.lang.javascript.psi.util.JSUtils) TsLintState(com.intellij.lang.javascript.linter.tslint.config.TsLintState) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FileUtil(com.intellij.openapi.util.io.FileUtil) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) StringUtil(com.intellij.openapi.util.text.StringUtil) JSLanguageServiceUtil(com.intellij.lang.javascript.service.JSLanguageServiceUtil) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Set(java.util.Set) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) TsLintConfigurable(com.intellij.lang.javascript.linter.tslint.ui.TsLintConfigurable) Collectors(java.util.stream.Collectors) TsLintConfigFileSearcher(com.intellij.lang.javascript.linter.tslint.execution.TsLintConfigFileSearcher) Nullable(org.jetbrains.annotations.Nullable) TsLintFileFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintFileFixAction) List(java.util.List) com.intellij.lang.javascript.linter(com.intellij.lang.javascript.linter) JSLanguageServiceQueueImpl(com.intellij.lang.javascript.service.JSLanguageServiceQueueImpl) TsLintConfiguration(com.intellij.lang.javascript.linter.tslint.config.TsLintConfiguration) TsLintErrorFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintErrorFixAction) ProcessOutput(com.intellij.execution.process.ProcessOutput) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Optional(java.util.Optional) TsLintLanguageService(com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) TsLintState(com.intellij.lang.javascript.linter.tslint.config.TsLintState) TsLintLanguageService(com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with TsLintLanguageService

use of com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService in project intellij-plugins by JetBrains.

the class TsLintConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    super.apply();
    final TsLintState state = getExtendedState(TsLintConfiguration.class).getState();
    if (!StringUtil.isEmptyOrSpaces(state.getPackagePath()) && state.isAllowJs()) {
        if (!checkPackageVersionForJs(state.getPackagePath()))
            throw new ConfigurationException("Linting JavaScript is not supported for this version of TSLint.");
    }
    final TsLintLanguageService service = TsLintLanguageService.getService(myProject);
    service.terminateStartedProcess(false);
}
Also used : TsLintState(com.intellij.lang.javascript.linter.tslint.config.TsLintState) ConfigurationException(com.intellij.openapi.options.ConfigurationException) TsLintLanguageService(com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService) TsLintConfiguration(com.intellij.lang.javascript.linter.tslint.config.TsLintConfiguration)

Aggregations

TsLintState (com.intellij.lang.javascript.linter.tslint.config.TsLintState)3 TsLintLanguageService (com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService)3 TsLintConfiguration (com.intellij.lang.javascript.linter.tslint.config.TsLintConfiguration)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 AnnotationHolder (com.intellij.lang.annotation.AnnotationHolder)1 DialectDetector (com.intellij.lang.javascript.DialectDetector)1 DialectOptionHolder (com.intellij.lang.javascript.DialectOptionHolder)1 com.intellij.lang.javascript.linter (com.intellij.lang.javascript.linter)1 TsLintBundle (com.intellij.lang.javascript.linter.tslint.TsLintBundle)1 TsLintConfigFileSearcher (com.intellij.lang.javascript.linter.tslint.execution.TsLintConfigFileSearcher)1 TsLinterError (com.intellij.lang.javascript.linter.tslint.execution.TsLinterError)1 TsLintErrorFixAction (com.intellij.lang.javascript.linter.tslint.fix.TsLintErrorFixAction)1 TsLintFileFixAction (com.intellij.lang.javascript.linter.tslint.fix.TsLintFileFixAction)1 TsLintConfigurable (com.intellij.lang.javascript.linter.tslint.ui.TsLintConfigurable)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1