Skip to content

Commit

Permalink
Merge pull request #119 from mkslanc/ignore-errors-by-message
Browse files Browse the repository at this point in the history
Add ability to filter typescript and python services by error messages
  • Loading branch information
anijanyan authored May 16, 2024
2 parents dcbe802 + 655548d commit 9fe8115
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
20 changes: 13 additions & 7 deletions packages/ace-linters/src/language-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,23 @@ export class LanguageProvider {
return new LanguageProvider(messageController, options);
}

/**
* method to create LanguageProvider from CDN
* @param customServices
* @param options
* @param includeDefaultLinters by default would include all linters
*/
static fromCdn(customServices: {
services: ServiceStruct[],
serviceManagerCdn: string,
includeDefaultLinters?: { [name in SupportedServices]: boolean | undefined } | true
}, options?: ProviderOptions): LanguageProvider
static fromCdn(cdnUrl: string, options?: ProviderOptions): LanguageProvider
includeDefaultLinters?: { [name in SupportedServices]?: boolean } | boolean
}, options?: ProviderOptions, includeDefaultLinters?: { [name in SupportedServices]?: boolean } | boolean): LanguageProvider
static fromCdn(cdnUrl: string, options?: ProviderOptions, includeDefaultLinters?: { [name in SupportedServices]?: boolean } | boolean): LanguageProvider
static fromCdn(source: string | {
services: ServiceStruct[],
serviceManagerCdn: string,
includeDefaultLinters?: { [name in SupportedServices]: boolean | undefined } | boolean
}, options?: ProviderOptions) {
includeDefaultLinters?: { [name in SupportedServices]?: boolean } | boolean
}, options?: ProviderOptions, includeDefaultLinters?: { [name in SupportedServices]?: boolean } | boolean) {
let messageController: IMessageController;
let worker: Worker;
if (typeof source === "string") {
Expand All @@ -83,15 +89,15 @@ export class LanguageProvider {
if (source[source.length - 1] == "/") {
source = source.substring(0, source.length - 1);
}
worker = createWorker(source);
worker = createWorker(source, includeDefaultLinters);
} else {
if (source.includeDefaultLinters == undefined) {
source.includeDefaultLinters = true;
}
worker = createWorker({
services: source.services,
serviceManagerCdn: source.serviceManagerCdn
}, source.includeDefaultLinters);
}, source.includeDefaultLinters ?? includeDefaultLinters);
}
messageController = new MessageController(worker);
return new LanguageProvider(messageController, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import * as lsp from "vscode-languageserver-protocol";
import {DiagnosticSeverity} from "vscode-languageserver-protocol";
import {FilterDiagnosticsOptions} from "../../types/language-service";
import {filterDiagnostics} from "../../type-converters/lsp/lsp-converters";

export function toRange(location: { row: number, column: number }, endLocation: { row: number, column: number }): lsp.Range {
return {
Expand All @@ -19,7 +20,7 @@ export function toRange(location: { row: number, column: number }, endLocation:
}

export function toDiagnostics(diagnostics: Diagnostic[], filterErrors: FilterDiagnosticsOptions): lsp.Diagnostic[] {
return diagnostics.filter((el) => !filterErrors.errorCodesToIgnore!.includes(el.code)).map((el) => {
const lspDiagnostics = diagnostics.filter((el) => !filterErrors.errorCodesToIgnore!.includes(el.code)).map((el) => {
let severity: DiagnosticSeverity = DiagnosticSeverity.Error;
if (filterErrors.errorCodesToTreatAsWarning!.includes(el.code)) {
severity = DiagnosticSeverity.Warning;
Expand All @@ -32,4 +33,6 @@ export function toDiagnostics(diagnostics: Diagnostic[], filterErrors: FilterDia
severity: severity,
}
});

return filterDiagnostics(lspDiagnostics, filterErrors);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {TextDocument} from "vscode-languageserver-textdocument";
import {CommonConverter} from "../../type-converters/common-converters";
import convertKind = CommonConverter.convertKind;
import {FilterDiagnosticsOptions} from "../../types/language-service";
import {filterDiagnostics} from "../../type-converters/lsp/lsp-converters";

export function fromTsDiagnostics(diagnostics: Diagnostic[], doc: TextDocument, filterErrors: FilterDiagnosticsOptions): lsp.Diagnostic[] {
return diagnostics.filter((el) => !filterErrors.errorCodesToIgnore!.includes(el.code.toString())).map((el) => {
const lspDiagnostics =diagnostics.filter((el) => !filterErrors.errorCodesToIgnore!.includes(el.code.toString())).map((el) => {
let start = el.start ?? 0;
let length = el.length ?? 1; //TODO:
if (filterErrors.errorCodesToTreatAsWarning!.includes(el.code.toString())) {
Expand All @@ -26,6 +27,7 @@ export function fromTsDiagnostics(diagnostics: Diagnostic[], doc: TextDocument,
return lsp.Diagnostic.create(lsp.Range.create(doc.positionAt(start), doc.positionAt(start + length)),
parseMessageText(el.messageText, el.code), fromTsCategory(el.category));
});
return filterDiagnostics(lspDiagnostics, filterErrors);
}

export function toTsOffset(range: lsp.Range, doc: TextDocument) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-linters/src/types/language-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ interface ExtraLib {
version: number;
}

export interface TsServiceOptions extends ServiceOptionsWithErrorCodes{
export interface TsServiceOptions extends ServiceOptionsWithErrorCodes, ServiceOptionsWithErrorMessages{
compilerOptions?: ts.CompilerOptions | ts.CompilerOptionsWithoutEnums,
extraLibs?: {
[path: string]: ExtraLib;
Expand Down Expand Up @@ -154,7 +154,7 @@ export interface JavascriptServiceOptions extends ServiceOptionsWithErrorMessage
rules?: { [rule: string]: any }
}

export interface PythonServiceOptions extends ServiceOptionsWithErrorCodes{
export interface PythonServiceOptions extends ServiceOptionsWithErrorCodes, ServiceOptionsWithErrorMessages{
configuration: { [name: string]: any }
}

Expand Down
18 changes: 14 additions & 4 deletions packages/ace-linters/types/language-provider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ export declare class LanguageProvider {
* @param {ProviderOptions} options
*/
static create(worker: Worker, options?: ProviderOptions): LanguageProvider;
/**
* method to create LanguageProvider from CDN
* @param customServices
* @param options
* @param includeDefaultLinters by default would include all linters
*/
static fromCdn(customServices: {
services: ServiceStruct[];
serviceManagerCdn: string;
includeDefaultLinters?: {
[name in SupportedServices]: boolean | undefined;
} | true;
}, options?: ProviderOptions): LanguageProvider;
static fromCdn(cdnUrl: string, options?: ProviderOptions): LanguageProvider;
[name in SupportedServices]?: boolean;
} | boolean;
}, options?: ProviderOptions, includeDefaultLinters?: {
[name in SupportedServices]?: boolean;
} | boolean): LanguageProvider;
static fromCdn(cdnUrl: string, options?: ProviderOptions, includeDefaultLinters?: {
[name in SupportedServices]?: boolean;
} | boolean): LanguageProvider;
setProviderOptions(options?: ProviderOptions): void;
private $registerSession;
private $getSessionLanguageProvider;
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-linters/types/types/language-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ interface ExtraLib {
content: string;
version: number;
}
export interface TsServiceOptions extends ServiceOptionsWithErrorCodes {
export interface TsServiceOptions extends ServiceOptionsWithErrorCodes, ServiceOptionsWithErrorMessages {
compilerOptions?: ts.CompilerOptions | ts.CompilerOptionsWithoutEnums;
extraLibs?: {
[path: string]: ExtraLib;
Expand Down Expand Up @@ -133,7 +133,7 @@ export interface JavascriptServiceOptions extends ServiceOptionsWithErrorMessage
[rule: string]: any;
};
}
export interface PythonServiceOptions extends ServiceOptionsWithErrorCodes {
export interface PythonServiceOptions extends ServiceOptionsWithErrorCodes, ServiceOptionsWithErrorMessages {
configuration: {
[name: string]: any;
};
Expand Down

0 comments on commit 9fe8115

Please sign in to comment.