Skip to content

Commit e362b00

Browse files
committed
Add mock-vue plugin to harnessLanguageService.
1. The structure is there but the contents are wrong. 2. There is no test that uses this mock plugin yet. 3. I still need to delete the existing fourslash/vuePlugin.ts
1 parent 0472839 commit e362b00

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

src/harness/harnessLanguageService.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,82 @@ namespace Harness.LanguageService {
785785
}),
786786
error: undefined
787787
};
788+
case "mock-vue":
789+
return {
790+
module: () => ({
791+
create(info: ts.server.PluginCreateInfo) {
792+
return info;
793+
},
794+
changeSourceFiles() {
795+
const clssf = ts.createLanguageServiceSourceFile;
796+
const ulssf = ts.updateLanguageServiceSourceFile;
797+
return {
798+
createLanguageServiceSourceFile(fileName: string, scriptSnapshot: ts.IScriptSnapshot, scriptTarget: ts.ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ts.ScriptKind): ts.SourceFile {
799+
if (interested(fileName)) {
800+
const wrapped = scriptSnapshot;
801+
scriptSnapshot = {
802+
getChangeRange: old => wrapped.getChangeRange(old),
803+
getLength: () => wrapped.getLength(),
804+
getText: (start, end) => parse(fileName, wrapped.getText(0, wrapped.getLength())).slice(start, end),
805+
};
806+
}
807+
var sourceFile = clssf(fileName, scriptSnapshot, scriptTarget, version, setNodeParents, scriptKind);
808+
if (interested(fileName)) {
809+
modifyVueSource(sourceFile);
810+
}
811+
return sourceFile;
812+
},
813+
updateLanguageServiceSourceFile(sourceFile: ts.SourceFile, scriptSnapshot: ts.IScriptSnapshot, version: string, textChangeRange: ts.TextChangeRange, aggressiveChecks?: boolean): ts.SourceFile {
814+
if (interested(sourceFile.fileName)) {
815+
const wrapped = scriptSnapshot;
816+
scriptSnapshot = {
817+
getChangeRange: old => wrapped.getChangeRange(old),
818+
getLength: () => wrapped.getLength(),
819+
getText: (start, end) => parse(sourceFile.fileName, wrapped.getText(0, wrapped.getLength())).slice(start, end),
820+
};
821+
}
822+
var sourceFile = ulssf(sourceFile, scriptSnapshot, version, textChangeRange, aggressiveChecks);
823+
if (interested(sourceFile.fileName)) {
824+
modifyVueSource(sourceFile);
825+
}
826+
return sourceFile;
827+
}
828+
}
829+
830+
function interested(filename: string) {
831+
return filename.length;
832+
}
833+
function modifyVueSource(sourcefile: ts.SourceFile) {
834+
return sourcefile;
835+
}
836+
function parse(filename: string, text: string) {
837+
return interested(filename) ? text : text;
838+
}
839+
},
840+
resolveModules() {
841+
return (rmn: any) =>
842+
(moduleName: string, containingFile: string, compilerOptions: ts.CompilerOptions, host: ts.ModuleResolutionHost, cache?: ts.ModuleResolutionCache) => {
843+
if (importInterested(moduleName)) {
844+
return {
845+
resolvedModule: {
846+
extension: ts.Extension.Ts,
847+
isExternalLibraryImport: true,
848+
// TODO: Fake this
849+
resolvedFileName: path.join(path.dirname(containingFile), path.basename(moduleName)),
850+
}
851+
}
852+
}
853+
else {
854+
return rmn(moduleName, containingFile, compilerOptions, host, cache);
855+
}
856+
};
857+
function importInterested(filename: string) {
858+
return filename.length;
859+
}
860+
}
861+
}),
862+
error: undefined
863+
};
788864

789865
default:
790866
return {

0 commit comments

Comments
 (0)