/
CSpellReporter.ts
123 lines (102 loc) · 3.02 KB
/
CSpellReporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { TextDocumentOffset, TextOffset } from './TextOffset';
export interface Suggestion {
/**
* Word to suggest.
*/
word: string;
/**
* `true` - if this suggestion can be an automatic fix.
*/
isPreferred?: boolean;
}
export interface Issue extends Omit<TextDocumentOffset, 'doc'> {
/** text surrounding the issue text */
context: TextOffset;
/**
* true if the issue has been flagged as a forbidden word.
*/
isFlagged?: boolean;
/**
* An optional array of replacement strings.
*/
suggestions?: string[];
/**
* An optional array of suggestions.
*/
suggestionsEx?: Suggestion[];
/**
* Issues are spelling issues unless otherwise specified.
*/
issueType?: IssueType;
/**
* Optional message to show.
*/
message?: string;
}
export enum IssueType {
spelling = 0,
directive = 1,
}
export type MessageType = 'Debug' | 'Info' | 'Warning';
export type MessageTypeLookup = {
[key in MessageType]: key;
};
export const MessageTypes: MessageTypeLookup = {
Debug: 'Debug',
Info: 'Info',
Warning: 'Warning',
};
export type MessageEmitter = (message: string, msgType: MessageType) => void;
export type DebugEmitter = (message: string) => void;
export type ErrorLike = Error | { message: string; name: string; toString: () => string };
export type ErrorEmitter = (message: string, error: ErrorLike) => void;
export type SpellingErrorEmitter = (issue: Issue) => void;
export type ProgressTypes = 'ProgressFileBegin' | 'ProgressFileComplete';
export type ProgressItem = ProgressFileBegin | ProgressFileComplete;
export interface ProgressBase {
type: ProgressTypes;
}
export interface ProgressFileBase extends ProgressBase {
type: ProgressTypes;
fileNum: number;
fileCount: number;
filename: string;
}
export interface ProgressFileComplete extends ProgressFileBase {
type: 'ProgressFileComplete';
elapsedTimeMs: number | undefined;
processed: boolean | undefined;
numErrors: number | undefined;
cached?: boolean;
}
/**
* Notification sent just before processing a file.
*/
export interface ProgressFileBegin extends ProgressFileBase {
type: 'ProgressFileBegin';
}
export type ProgressEmitter = (p: ProgressItem | ProgressFileComplete) => void;
export interface RunResult {
/** Number of files processed. */
files: number;
/** Set of files where issues were found. */
filesWithIssues: Set<string>;
/** Number of issues found. */
issues: number;
/** Number of processing errors. */
errors: number;
/** Number files that used results from the cache. */
cachedFiles?: number;
}
export type ResultEmitter = (result: RunResult) => void | Promise<void>;
export interface CSpellReporter {
issue: SpellingErrorEmitter;
info: MessageEmitter;
debug: DebugEmitter;
error: ErrorEmitter;
progress: ProgressEmitter;
result: ResultEmitter;
}
export interface CSpellReporterModule {
getReporter: (settings: unknown) => CSpellReporter;
}