Compare commits

...

33 commits

Author SHA1 Message Date
Nathan Shively-Sanders cb8d74ac2f Remove original vue-ts-plugin fourslash test 2017-03-27 15:17:29 -07:00
Nathan Shively-Sanders c04cb33a28 Clean up mock-vue plugin a little 2017-03-27 15:16:15 -07:00
Nathan Shively-Sanders ff5f5d1cca Add vue-ts-plugin-based test.
Based on the same test style as the ng-ts-plugin-based tests.
2017-03-27 15:05:52 -07:00
Nathan Shively-Sanders df6c1cc961 Move create/update override to a separate hook. 2017-03-27 15:05:19 -07:00
Nathan Shively-Sanders e362b0023a 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
2017-03-20 14:12:52 -07:00
Nathan Shively-Sanders 0472839b8f Merge branch 'master' into vue-plugin-WIP 2017-03-20 13:40:02 -07:00
Nathan Shively-Sanders 5fc16ced20 Merge branch 'master' into vue-plugin-WIP 2017-03-07 10:24:38 -08:00
Nathan Shively-Sanders d1c2d862b9 Merge branch 'master' into vue-plugin-WIP 2017-03-07 10:23:27 -08:00
Nathan Shively-Sanders cda045ce80 Get rid of cheat parameter to create/updateLanguageServiceSourceFile 2017-03-02 15:31:06 -08:00
Nathan Shively-Sanders ab1fc019d5 Cleanup: remove more comments 2017-03-02 13:35:37 -08:00
Nathan Shively-Sanders ac03583a07 Still more changes reverted 2017-03-02 13:32:03 -08:00
Nathan Shively-Sanders 881884a6e2 Revert more unneeded changes 2017-03-02 13:31:14 -08:00
Nathan Shively-Sanders 51408f0a0d Allow plugins to override lshost.resolveModuleName
The implementation is ugly and probably still a little bit wrong.
2017-03-02 13:10:56 -08:00
Nathan Shively-Sanders 7def921610 Remove range parameter, passing cheater text instead
Now the diff is isolated to the services layer, although it's a hackier
change. I'll think of a way to make it cleaner.
2017-03-01 16:28:43 -08:00
Nathan Shively-Sanders 5f2443a26c Pass range around inside the update[LanguageService]SourceFile tree 2017-02-28 16:28:26 -08:00
Nathan Shively-Sanders 6cf7194082 Add new interface to overwrite create/updateLanguageServiceSourceFile 2017-02-28 14:54:59 -08:00
Nathan Shively-Sanders 2693d3fec1 Add range parameter:createLanguageServiceSourceFile 2017-02-28 11:01:59 -08:00
Nathan Shively-Sanders b65c45994a Remove (most) of vue-specific code from parser
createSourceFile now allows you to pass in a range that specifies how
much of the file you're actually interested in.
2017-02-24 16:12:35 -08:00
Nathan Shively-Sanders ad12198188 Remove even more ".vue" (from core.ts this time) 2017-02-23 15:46:42 -08:00
Nathan Shively-Sanders fd19e54090 More cleanup.
Everything seems to be working now.
So that's good.
2017-02-23 15:34:22 -08:00
Nathan Shively-Sanders 62c686aacb Remove explicit "VUE" support from server.
It wasn't doing anything anyway.
2017-02-23 15:08:51 -08:00
Nathan Shively-Sanders 779a3930a4 Remove ScriptKind.VUE, convert to External
All the special casing is still there though, just for external now. So
more changes needed.
2017-02-23 14:55:59 -08:00
Nathan Shively-Sanders bf0227a967 Synthetic import should have no decorators or modifiers at all 2017-02-23 14:34:01 -08:00
Nathan Shively-Sanders c87a647add Update vue Plugin tests
1. Everything basically works
2. Actual interaction with the language service is kind of broken.
3. The implementation is completely wrong!
2017-02-23 10:32:54 -08:00
Nathan Shively-Sanders 7f91c780c1 Insert import { Vue } from './vue' statement in .vue files 2017-02-23 10:05:46 -08:00
Nathan Shively-Sanders 29e461f3a4 Get inserted new Vue call working 2017-02-22 16:22:20 -08:00
Nathan Shively-Sanders b6a4bbf4dc Improve vue-like test 2017-02-22 13:46:57 -08:00
Nathan Shively-Sanders 27869b53c8 Add new Vue call around an export default object
Doesn't work though.
2017-02-22 13:46:11 -08:00
Nathan Shively-Sanders 8100a16176 Only parse text inside script tag of .vue files 2017-02-22 09:43:41 -08:00
Nathan Shively-Sanders 0a3738d8a7 Update vue test now that it passes 2017-02-22 09:42:43 -08:00
Nathan Shively-Sanders 79addfd5c7 Initial fourslash test
Possibly the wrong layer for this, but convenient for hacking.
2017-02-21 15:32:06 -08:00
Nathan Shively-Sanders 0610d5fb51 Hacking around in the parser.
Which is probably the wrong place.
2017-02-21 15:31:27 -08:00
Nathan Shively-Sanders 9316f14e1d Manually add VUE a few places.
Maybe enough places? I'm not good at debugging the language service or
server, so could be not.
2017-02-21 10:14:55 -08:00
5 changed files with 134 additions and 3 deletions

View file

@ -785,6 +785,71 @@ namespace Harness.LanguageService {
}),
error: undefined
};
case "mock-vue":
return {
module: () => ({
create(info: ts.server.PluginCreateInfo) {
const clssf = ts.createLanguageServiceSourceFile;
const ulssf = ts.updateLanguageServiceSourceFile;
ts.overrideCreateupdateLanguageServiceSourceFile(
(fileName, scriptSnapshot, scriptTarget, version, setNodeParents, scriptKind?) => {
if (interested(fileName)) {
const wrapped = scriptSnapshot;
scriptSnapshot = {
getChangeRange: old => wrapped.getChangeRange(old),
getLength: () => wrapped.getLength(),
getText: (start, end) => parse(wrapped.getText(0, wrapped.getLength())).slice(start, end),
};
}
var sourceFile = clssf(fileName, scriptSnapshot, scriptTarget, version, setNodeParents, scriptKind);
return sourceFile;
},
(sourceFile, scriptSnapshot, version, textChangeRange, aggressiveChecks?) => {
if (interested(sourceFile.fileName)) {
const wrapped = scriptSnapshot;
scriptSnapshot = {
getChangeRange: old => wrapped.getChangeRange(old),
getLength: () => wrapped.getLength(),
getText: (start, end) => parse(wrapped.getText(0, wrapped.getLength())).slice(start, end),
};
}
var sourceFile = ulssf(sourceFile, scriptSnapshot, version, textChangeRange, aggressiveChecks);
return sourceFile;
});
return makeDefaultProxy(info);
function interested(filename: string) {
return filename.length;
}
function parse(text: string) {
const start = text.indexOf("<script>") + "<script>".length;
const end = text.indexOf("</script>");
return text.slice(0, start).replace(/./g, ' ') + text.slice(start, end) + text.slice(end).replace(/./g, ' ');
}
},
resolveModules() {
return (rmn: any) =>
(moduleName: string, containingFile: string, compilerOptions: ts.CompilerOptions, host: ts.ModuleResolutionHost, cache?: ts.ModuleResolutionCache) => {
if (importInterested(moduleName)) {
return {
resolvedModule: {
extension: ts.Extension.Ts,
isExternalLibraryImport: true,
resolvedFileName: containingFile.slice(0, containingFile.lastIndexOf("/")) + "/" + moduleName,
}
}
}
else {
return rmn(moduleName, containingFile, compilerOptions, host, cache);
}
};
function importInterested(filename: string) {
return filename.charAt(0) === "." && filename.slice(-4) === ".vue";
}
}
}),
error: undefined
};
default:
return {

View file

@ -11,7 +11,7 @@ namespace ts.server {
private filesWithChangedSetOfUnresolvedImports: Path[];
private readonly resolveModuleName: typeof resolveModuleName;
private resolveModuleName: typeof resolveModuleName;
readonly trace: (s: string) => void;
readonly realpath?: (path: string) => string;
@ -46,6 +46,11 @@ namespace ts.server {
}
}
public overrideResolveModuleName(plugin: PluginResolveModules) {
const prevResolveModuleName = this.resolveModuleName;
this.resolveModuleName = plugin(prevResolveModuleName);
}
public startRecordingFilesWithChangedResolutions() {
this.filesWithChangedSetOfUnresolvedImports = [];
}
@ -237,4 +242,4 @@ namespace ts.server {
this.compilationSettings = opt;
}
}
}
}

View file

@ -102,6 +102,13 @@ namespace ts.server {
export interface PluginModule {
create(createInfo: PluginCreateInfo): LanguageService;
getExternalFiles?(proj: Project): string[];
resolveModules?(createInfo: PluginCreateInfo): PluginResolveModules;
}
export type ModuleResolver = (moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache) => ResolvedModuleWithFailedLookupLocations;
export type PluginResolveModules = {
(plugin: ModuleResolver): ModuleResolver;
}
export interface PluginModuleFactory {
@ -904,6 +911,9 @@ namespace ts.server {
const pluginModule = pluginModuleFactory({ typescript: ts });
this.languageService = pluginModule.create(info);
if (pluginModule.resolveModules) {
this.lsHost.overrideResolveModuleName(pluginModule.resolveModules(info));
}
this.plugins.push(pluginModule);
}
catch (e) {
@ -1083,4 +1093,4 @@ namespace ts.server {
this.typeAcquisition = newTypeAcquisition;
}
}
}
}

View file

@ -891,6 +891,13 @@ namespace ts {
sourceFile.scriptSnapshot = scriptSnapshot;
}
export function overrideCreateupdateLanguageServiceSourceFile(
create: (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind, cheat?: string) => SourceFile,
update: (sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean, cheat?: string) => SourceFile) {
ts.createLanguageServiceSourceFile = create;
ts.updateLanguageServiceSourceFile = update;
}
export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile {
const text = scriptSnapshot.getText(0, scriptSnapshot.getLength());
const sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents, scriptKind);

View file

@ -0,0 +1,44 @@
/// <reference path="../fourslash.ts"/>
// @Filename: tsconfig.json
//// {
//// "compilerOptions": {
//// "allowNonTsExtensions": true,
//// "plugins": [
//// { "name": "mock-vue" }
//// ]
//// },
//// "files": ["a.vue"]
//// }
// Note: This test does *not* implement the correct vue transformation.
// So it's other.data.property, not other.property or other.$data.property
// @Filename: other.vue
////<template>
////</template>
////<script>
////export default {
//// data: { property: "Example" }
////}
////</script>
////<style>
////</style>
// @Filename: a.vue
////<template>
////</template>
////<script>
////import other from './other.vue'
//// other.data.property/**/
////export default {
//// data: { greeting: "Hello" }
////}
////</script>
////<style>
////</style>
// LS shouldn't crash/fail if a plugin fails to init correctly
goTo.marker();
verify.quickInfoIs('(property) property: string');
verify.numberOfErrorsInCurrentFile(0);