Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Misti static analyzer to display #26

Merged
merged 5 commits into from
Feb 14, 2025
Merged

Conversation

skulidropek
Copy link
Contributor

@skulidropek skulidropek commented Feb 4, 2025

#22

Added a class responsible for parsing Misti analyses.

Now we need to fix CompilerInspection
Like this:

import * as lsp from "vscode-languageserver";
import { File } from "@server/psi/File";
import { MistiCompiler, Severity, CompilerError } from "@server/compiler/MistiCompiler";
import { URI } from "vscode-uri";
import { Logger } from "@server/utils/logger";

export class CompilerInspection {
    async inspect(file: File): Promise<lsp.Diagnostic[]> {
        if (file.fromStdlib) return [];
        try {
            const filePath = URI.parse(file.uri).fsPath;
            const errors = await MistiCompiler.compile(filePath);
            return errors.map((error: CompilerError) => ({
                severity: this.mapSeverity(error.severity),
                range: {
                    start: {
                        line: error.line,
                        character: error.character,
                    },
                    end: {
                        line: error.line,
                        character: error.character + (error.length ?? 1),
                    },
                },
                message: error.message,
                source: "misti",
                code: "misti-warning",
            }));
        } catch (err) {
            Logger.getInstance().error(`Misti compiler error: ${String(err)}`);
            return [];
        }
    }

    private mapSeverity(severity: Severity): lsp.DiagnosticSeverity {
        switch (severity) {
            case Severity.INFO:
                return lsp.DiagnosticSeverity.Information;
            case Severity.LOW:
            case Severity.MEDIUM:
                return lsp.DiagnosticSeverity.Warning;
            case Severity.HIGH:
            case Severity.CRITICAL:
                return lsp.DiagnosticSeverity.Error;
            default:
                return lsp.DiagnosticSeverity.Warning;
        }
    }
}

@skulidropek skulidropek force-pushed the misti branch 2 times, most recently from 7e80d94 to 634c3f2 Compare February 4, 2025 08:42
@i582
Copy link
Collaborator

i582 commented Feb 14, 2025

Hey, thank you! I'll merge it for now and then improve the code further

@i582 i582 merged commit fa5b364 into tact-lang:master Feb 14, 2025
4 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants