mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Add test for configurePlugin
This commit is contained in:
parent
4273fd7d55
commit
db914d8739
@ -684,6 +684,10 @@ namespace ts.server {
|
||||
return response.body!.map(entry => this.decodeSpan(entry, fileName)); // TODO: GH#18217
|
||||
}
|
||||
|
||||
configurePlugin(pluginName: string, configuration: any): void {
|
||||
this.processRequest<protocol.ConfigurePluginRequest>("configurePlugin", { pluginName, configuration });
|
||||
}
|
||||
|
||||
getIndentationAtPosition(_fileName: string, _position: number, _options: EditorOptions): number {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
@ -3400,6 +3400,10 @@ Actual: ${stringify(fullActual)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public configurePlugin(pluginName: string, configuration: any): void {
|
||||
(<ts.server.SessionClient>this.languageService).configurePlugin(pluginName, configuration);
|
||||
}
|
||||
}
|
||||
|
||||
function updateTextRangeForTextChanges({ pos, end }: ts.TextRange, textChanges: ReadonlyArray<ts.TextChange>): ts.TextRange {
|
||||
@ -3463,19 +3467,20 @@ Actual: ${stringify(fullActual)}`);
|
||||
function runCode(code: string, state: TestState): void {
|
||||
// Compile and execute the test
|
||||
const wrappedCode =
|
||||
`(function(test, goTo, verify, edit, debug, format, cancellation, classification, verifyOperationIsCancelled) {
|
||||
`(function(test, goTo, plugins, verify, edit, debug, format, cancellation, classification, verifyOperationIsCancelled) {
|
||||
${code}
|
||||
})`;
|
||||
try {
|
||||
const test = new FourSlashInterface.Test(state);
|
||||
const goTo = new FourSlashInterface.GoTo(state);
|
||||
const plugins = new FourSlashInterface.Plugins(state);
|
||||
const verify = new FourSlashInterface.Verify(state);
|
||||
const edit = new FourSlashInterface.Edit(state);
|
||||
const debug = new FourSlashInterface.Debug(state);
|
||||
const format = new FourSlashInterface.Format(state);
|
||||
const cancellation = new FourSlashInterface.Cancellation(state);
|
||||
const f = eval(wrappedCode);
|
||||
f(test, goTo, verify, edit, debug, format, cancellation, FourSlashInterface.Classification, verifyOperationIsCancelled);
|
||||
f(test, goTo, plugins, verify, edit, debug, format, cancellation, FourSlashInterface.Classification, verifyOperationIsCancelled);
|
||||
}
|
||||
catch (err) {
|
||||
throw err;
|
||||
@ -3975,6 +3980,15 @@ namespace FourSlashInterface {
|
||||
}
|
||||
}
|
||||
|
||||
export class Plugins {
|
||||
constructor (private state: FourSlash.TestState) {
|
||||
}
|
||||
|
||||
public configurePlugin(pluginName: string, configuration: any): void {
|
||||
this.state.configurePlugin(pluginName, configuration);
|
||||
}
|
||||
}
|
||||
|
||||
export class GoTo {
|
||||
constructor(private state: FourSlash.TestState) {
|
||||
}
|
||||
|
||||
@ -833,6 +833,36 @@ namespace Harness.LanguageService {
|
||||
error: undefined
|
||||
};
|
||||
|
||||
// Accepts configurations
|
||||
case "configurable-diagnostic-adder":
|
||||
let customMessage = "default message";
|
||||
return {
|
||||
module: () => ({
|
||||
create(info: ts.server.PluginCreateInfo) {
|
||||
customMessage = info.config.message;
|
||||
const proxy = makeDefaultProxy(info);
|
||||
proxy.getSemanticDiagnostics = filename => {
|
||||
const prev = info.languageService.getSemanticDiagnostics(filename);
|
||||
const sourceFile: ts.SourceFile = info.project.getSourceFile(ts.toPath(filename, /*basePath*/ undefined, ts.createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
|
||||
prev.push({
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
file: sourceFile,
|
||||
code: 9999,
|
||||
length: 3,
|
||||
messageText: customMessage,
|
||||
start: 0
|
||||
});
|
||||
return prev;
|
||||
};
|
||||
return proxy;
|
||||
},
|
||||
onConfigurationChanged(config: any) {
|
||||
customMessage = config.message;
|
||||
}
|
||||
}),
|
||||
error: undefined
|
||||
};
|
||||
|
||||
default:
|
||||
return {
|
||||
module: undefined,
|
||||
|
||||
@ -124,6 +124,9 @@ declare namespace FourSlashInterface {
|
||||
symbolsInScope(range: Range): any[];
|
||||
setTypesRegistry(map: { [key: string]: void }): void;
|
||||
}
|
||||
class plugins {
|
||||
configurePlugin(pluginName: string, configuration: any): void;
|
||||
}
|
||||
class goTo {
|
||||
marker(name?: string | Marker): void;
|
||||
eachMarker(markers: ReadonlyArray<string>, action: (marker: Marker, index: number) => void): void;
|
||||
@ -651,6 +654,7 @@ declare namespace FourSlashInterface {
|
||||
}
|
||||
declare function verifyOperationIsCancelled(f: any): void;
|
||||
declare var test: FourSlashInterface.test_;
|
||||
declare var plugins: FourSlashInterface.plugins;
|
||||
declare var goTo: FourSlashInterface.goTo;
|
||||
declare var verify: FourSlashInterface.verify;
|
||||
declare var edit: FourSlashInterface.edit;
|
||||
|
||||
22
tests/cases/fourslash/server/configurePlugin.ts
Normal file
22
tests/cases/fourslash/server/configurePlugin.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/// <reference path="../fourslash.ts"/>
|
||||
|
||||
// @Filename: tsconfig.json
|
||||
//// {
|
||||
//// "compilerOptions": {
|
||||
//// "plugins": [
|
||||
//// { "name": "configurable-diagnostic-adder" , "message": "configured error" }
|
||||
//// ]
|
||||
//// },
|
||||
//// "files": ["a.ts"]
|
||||
//// }
|
||||
|
||||
// @Filename: a.ts
|
||||
//// let x = [1, 2];
|
||||
//// /**/
|
||||
////
|
||||
|
||||
// Test that plugin adds an error message which is able to be configured
|
||||
goTo.marker();
|
||||
verify.getSemanticDiagnostics([{ message: "configured error", code: 9999, range: { pos: 0, end: 3, fileName: "a.ts" } }]);
|
||||
plugins.configurePlugin("configurable-diagnostic-adder", { message: "new error" });
|
||||
verify.getSemanticDiagnostics([{ message: "new error", code: 9999, range: { pos: 0, end: 3, fileName: "a.ts" } }]);
|
||||
Loading…
x
Reference in New Issue
Block a user