UNPKG

3.67 kBTypeScriptView Raw
1import * as linter from "atom/linter";
2import { Diagnostic, LanguageClientConnection, PublishDiagnosticsParams } from "../languageclient";
3/**
4 * Public: Listen to diagnostics messages from the language server and publish them to the user by way of the Linter
5 * Push (Indie) v2 API provided by the Base Linter package.
6 */
7export default class LinterPushV2Adapter {
8 protected _diagnosticMap: Map<string, linter.Message[]>;
9 /**
10 * A map from file path {linter.Message["location"]["file"]} to a Map of all Message keys to Diagnostics
11 * ${Map<linter.Message["key"], Diagnostic>} It has to be stored separately because a {Message} object cannot hold all
12 * of the information that a {Diagnostic} provides, thus we store the original {Diagnostic} object.
13 */
14 protected _lsDiagnosticMap: Map<linter.Message["location"]["file"], Map<linter.Message["key"], Diagnostic>>;
15 protected _indies: Set<linter.IndieDelegate>;
16 /**
17 * Public: Create a new {LinterPushV2Adapter} that will listen for diagnostics via the supplied {LanguageClientConnection}.
18 *
19 * @param connection A {LanguageClientConnection} to the language server that will provide diagnostics.
20 */
21 constructor(connection: LanguageClientConnection);
22 /** Dispose this adapter ensuring any resources are freed and events unhooked. */
23 dispose(): void;
24 /**
25 * Public: Attach this {LinterPushV2Adapter} to a given {V2IndieDelegate} registry.
26 *
27 * @param indie A {V2IndieDelegate} that wants to receive messages.
28 */
29 attach(indie: linter.IndieDelegate): void;
30 /** Public: Remove all {V2IndieDelegate} registries attached to this adapter and clear them. */
31 detachAll(): void;
32 /**
33 * Public: Capture the diagnostics sent from a langguage server, convert them to the Linter V2 format and forward them
34 * on to any attached {V2IndieDelegate}s.
35 *
36 * @param params The {PublishDiagnosticsParams} received from the language server that should be captured and
37 * forwarded on to any attached {V2IndieDelegate}s.
38 */
39 captureDiagnostics(params: PublishDiagnosticsParams): void;
40 /**
41 * Public: Convert a single {Diagnostic} received from a language server into a single {V2Message} expected by the
42 * Linter V2 API.
43 *
44 * @param path A string representing the path of the file the diagnostic belongs to.
45 * @param diagnostics A {Diagnostic} object received from the language server.
46 * @returns A {V2Message} equivalent to the {Diagnostic} object supplied by the language server.
47 */
48 diagnosticToV2Message(path: string, diagnostic: Diagnostic): linter.Message;
49 /**
50 * Public: get diagnostics for the given linter messages
51 *
52 * @param linterMessages An array of linter {V2Message}
53 * @returns An array of LS {Diagnostic[]}
54 */
55 getLSDiagnosticsForMessages(linterMessages: linter.Message[]): Diagnostic[];
56 /**
57 * Public: Get the {Diagnostic} that is associated with the given Base Linter v2 {Message}.
58 *
59 * @param message The {Message} object to fetch the {Diagnostic} for.
60 * @returns The associated {Diagnostic}.
61 */
62 getLSDiagnosticForMessage(message: linter.Message): Diagnostic | undefined;
63 /**
64 * Public: Convert a diagnostic severity number obtained from the language server into the textual equivalent for a
65 * Linter {V2Message}.
66 *
67 * @param severity A number representing the severity of the diagnostic.
68 * @returns A string of 'error', 'warning' or 'info' depending on the severity.
69 */
70 static diagnosticSeverityToSeverity(severity: number): "error" | "warning" | "info";
71}