@glint/tsserver-plugin 0.2.1 → 1.4.1-unstable.1d0d581
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/lib/typescript-server-plugin.d.ts +3 -0
- package/lib/typescript-server-plugin.d.ts.map +1 -0
- package/lib/typescript-server-plugin.js +114 -0
- package/lib/typescript-server-plugin.js.map +1 -0
- package/package.json +14 -14
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -57
- package/lib/language-service.d.ts +0 -32
- package/lib/language-service.js +0 -363
- package/lib/logging.d.ts +0 -11
- package/lib/logging.js +0 -53
- package/lib/patch/language-service-host.d.ts +0 -7
- package/lib/patch/language-service-host.js +0 -60
- package/lib/patch/lib.d.ts +0 -10
- package/lib/patch/lib.js +0 -101
- package/lib/path-transformation.d.ts +0 -15
- package/lib/path-transformation.js +0 -30
- package/lib/util/auto-import.d.ts +0 -3
- package/lib/util/auto-import.js +0 -105
- package/lib/util/logging.d.ts +0 -11
- package/lib/util/logging.js +0 -53
- package/lib/util/path-transformation.d.ts +0 -15
- package/lib/util/path-transformation.js +0 -30
- package/lib/virtual-module-manager.d.ts +0 -15
- package/lib/virtual-module-manager.js +0 -68
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glint/typescript-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TypeScript server plugin that performs type-checking.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[glint]: https://github.com/typed-ember/glint
|
|
5
|
+
Old Glint used the LanguageServer to perform type-checking; Glint 2 uses a TypeScript server plugin to follow suit with Volar.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript-server-plugin.d.ts","sourceRoot":"","sources":["../src/typescript-server-plugin.ts"],"names":[],"mappings":"AAsBA,QAAA,MAAM,MAAM,KAmDX,CAAC;AAEF,SAAS,MAAM,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const { createJiti } = require('jiti');
|
|
2
|
+
const jiti = createJiti(__filename);
|
|
3
|
+
const { createLanguageServicePlugin, } = require('@volar/typescript/lib/quickstart/createLanguageServicePlugin.js');
|
|
4
|
+
/**
|
|
5
|
+
* We use the jiti (https://github.com/unjs/jiti) runtime to make it possible to
|
|
6
|
+
* synchronously load the ESM glint libraries from the current CommonJS context.
|
|
7
|
+
* It is a requirement that TypeScript plugins are written in CommonJS, which poses issues
|
|
8
|
+
* with having Glint be authored in ESM due to the requirement that typically `await import`
|
|
9
|
+
* is required to load ESM modules from CJS. But with jiti we can synchronously load the ESM
|
|
10
|
+
* modules from CJS which lets us avoid a ton of hacks and complexity we (or Volar)
|
|
11
|
+
* would otherwise have to write to bridge the sync/async APIs.
|
|
12
|
+
*/
|
|
13
|
+
const glintCore = jiti('@glint/core');
|
|
14
|
+
const { VirtualGtsCode, LooseModeBackingComponentClassVirtualCode, augmentDiagnostics } = glintCore;
|
|
15
|
+
const plugin = createLanguageServicePlugin((ts, info) => {
|
|
16
|
+
const { findConfig, createEmberLanguagePlugin } = glintCore;
|
|
17
|
+
const cwd = info.languageServiceHost.getCurrentDirectory();
|
|
18
|
+
const glintConfig = findConfig(cwd);
|
|
19
|
+
// Uncomment as a smoke test to see if the plugin is running
|
|
20
|
+
const enableLogging = false;
|
|
21
|
+
if (glintConfig) {
|
|
22
|
+
if (enableLogging) {
|
|
23
|
+
info.project.projectService.logger.info('Glint TS Plugin is running!');
|
|
24
|
+
}
|
|
25
|
+
const gtsLanguagePlugin = createEmberLanguagePlugin(glintConfig);
|
|
26
|
+
return {
|
|
27
|
+
languagePlugins: [gtsLanguagePlugin],
|
|
28
|
+
setup: (language) => {
|
|
29
|
+
// project2Service.set(info.project, [
|
|
30
|
+
// language,
|
|
31
|
+
// info.languageServiceHost,
|
|
32
|
+
// info.languageService,
|
|
33
|
+
// ]);
|
|
34
|
+
info.languageService = proxyLanguageServiceForGlint(ts, language, info.languageService, (fileName) => fileName);
|
|
35
|
+
// #3963
|
|
36
|
+
// const timer = setInterval(() => {
|
|
37
|
+
// if (info.project['program']) {
|
|
38
|
+
// clearInterval(timer);
|
|
39
|
+
// info.project['program'].__glint__ = { language };
|
|
40
|
+
// }
|
|
41
|
+
// }, 50);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (enableLogging) {
|
|
47
|
+
info.project.projectService.logger.info('Glint TS Plugin is NOT running!');
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
languagePlugins: [],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
module.exports = plugin;
|
|
55
|
+
function proxyLanguageServiceForGlint(ts, language, // Language<T>,
|
|
56
|
+
languageService, asScriptId) {
|
|
57
|
+
const proxyCache = new Map();
|
|
58
|
+
const getProxyMethod = (target, p) => {
|
|
59
|
+
switch (p) {
|
|
60
|
+
// case 'getCompletionsAtPosition': return getCompletionsAtPosition(glintOptions, target[p]);
|
|
61
|
+
// case 'getCompletionEntryDetails': return getCompletionEntryDetails(language, asScriptId, target[p]);
|
|
62
|
+
// case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(target[p]);
|
|
63
|
+
// case 'getDefinitionAndBoundSpan': return getDefinitionAndBoundSpan(ts, language, languageService, glintOptions, asScriptId, target[p]);
|
|
64
|
+
// case 'getQuickInfoAtPosition': return getQuickInfoAtPosition(ts, target, target[p]);
|
|
65
|
+
// TS plugin only
|
|
66
|
+
// case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
|
|
67
|
+
case 'getSemanticDiagnostics':
|
|
68
|
+
return getSemanticDiagnostics(ts, language, languageService, asScriptId, target[p]);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return new Proxy(languageService, {
|
|
72
|
+
get(target, p, receiver) {
|
|
73
|
+
if (getProxyMethod) {
|
|
74
|
+
if (!proxyCache.has(p)) {
|
|
75
|
+
proxyCache.set(p, getProxyMethod(target, p));
|
|
76
|
+
}
|
|
77
|
+
const proxyMethod = proxyCache.get(p);
|
|
78
|
+
if (proxyMethod) {
|
|
79
|
+
return proxyMethod;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return Reflect.get(target, p, receiver);
|
|
83
|
+
},
|
|
84
|
+
set(target, p, value, receiver) {
|
|
85
|
+
return Reflect.set(target, p, value, receiver);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function getSemanticDiagnostics(ts, language, // Language<T>,
|
|
90
|
+
languageService, asScriptId, getSemanticDiagnostics) {
|
|
91
|
+
return (fileName) => {
|
|
92
|
+
const tsDiagnostics = getSemanticDiagnostics(fileName);
|
|
93
|
+
const program = languageService.getProgram();
|
|
94
|
+
const sourceScript = language.scripts.get(asScriptId(fileName));
|
|
95
|
+
if (!sourceScript?.generated) {
|
|
96
|
+
return tsDiagnostics;
|
|
97
|
+
}
|
|
98
|
+
const root = sourceScript.generated.root;
|
|
99
|
+
if (!(root instanceof VirtualGtsCode || root instanceof LooseModeBackingComponentClassVirtualCode)) {
|
|
100
|
+
return tsDiagnostics;
|
|
101
|
+
}
|
|
102
|
+
const transformedModule = root.transformedModule;
|
|
103
|
+
if (!transformedModule) {
|
|
104
|
+
return tsDiagnostics;
|
|
105
|
+
}
|
|
106
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
107
|
+
if (!sourceFile) {
|
|
108
|
+
return tsDiagnostics;
|
|
109
|
+
}
|
|
110
|
+
const augmentedTsDiagnostics = augmentDiagnostics(transformedModule, tsDiagnostics);
|
|
111
|
+
return augmentedTsDiagnostics;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=typescript-server-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript-server-plugin.js","sourceRoot":"","sources":["../src/typescript-server-plugin.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glint/tsserver-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.4.1-unstable.1d0d581",
|
|
4
|
+
"type": "commonjs",
|
|
4
5
|
"repository": "typed-ember/glint",
|
|
5
|
-
"description": "
|
|
6
|
+
"description": "TypeScript Server Plugin for Glint",
|
|
6
7
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
8
|
+
"main": "lib/typescript-server-plugin.js",
|
|
9
|
+
"authors": [
|
|
10
|
+
"Alex Matchneer (https://github.com/machty)"
|
|
11
|
+
],
|
|
10
12
|
"files": [
|
|
11
13
|
"README.md",
|
|
12
14
|
"lib"
|
|
13
15
|
],
|
|
14
16
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"test": "
|
|
17
|
+
"test": "echo 'no standalone tests within this project'",
|
|
18
|
+
"test:typecheck": "echo 'no standalone typecheck within this project'",
|
|
19
|
+
"test:tsc": "echo 'no standalone typecheck within this project'",
|
|
17
20
|
"build": "tsc --build",
|
|
18
21
|
"prepack": "yarn build"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"@glint/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"@types/jest": "^25.2.1",
|
|
26
|
-
"jest": "^25.5.4",
|
|
27
|
-
"ts-jest": "^25.4.0"
|
|
24
|
+
"jiti": "~2.4.2",
|
|
25
|
+
"@glint/core": "1.4.1-unstable.1d0d581",
|
|
26
|
+
"@volar/language-core": "2.4.12",
|
|
27
|
+
"@volar/typescript": "2.4.12"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const path_1 = __importDefault(require("path"));
|
|
6
|
-
const config_1 = require("@glint/config");
|
|
7
|
-
const virtual_module_manager_1 = __importDefault(require("./virtual-module-manager"));
|
|
8
|
-
const lib_1 = require("./patch/lib");
|
|
9
|
-
const language_service_host_1 = require("./patch/language-service-host");
|
|
10
|
-
const logging_1 = require("./util/logging");
|
|
11
|
-
const language_service_1 = __importDefault(require("./language-service"));
|
|
12
|
-
const init = ({ typescript: ts }) => {
|
|
13
|
-
const modules = new virtual_module_manager_1.default(ts);
|
|
14
|
-
lib_1.patchLib(ts, modules);
|
|
15
|
-
return {
|
|
16
|
-
create(info) {
|
|
17
|
-
let logger = logging_1.loggerFor(info);
|
|
18
|
-
let config = config_1.loadConfig(path_1.default.dirname(info.project.projectName));
|
|
19
|
-
logger.log('\nStarting @glint/tsserver-plugin at', new Date().toString());
|
|
20
|
-
language_service_host_1.patchLanguageServiceHost(config, info);
|
|
21
|
-
modules.addProject(config, info.project);
|
|
22
|
-
let glintService = new language_service_1.default(ts, modules, info);
|
|
23
|
-
let fullService = makeProxy(info.languageService, glintService);
|
|
24
|
-
if (info.config.logLanguageServiceMethodCalls) {
|
|
25
|
-
installMethodLogging(logger, fullService);
|
|
26
|
-
}
|
|
27
|
-
return fullService;
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
function makeProxy(base, glint) {
|
|
32
|
-
return new Proxy(base, {
|
|
33
|
-
get(_, key) {
|
|
34
|
-
if (key in glint) {
|
|
35
|
-
return glint[key];
|
|
36
|
-
}
|
|
37
|
-
return base[key];
|
|
38
|
-
},
|
|
39
|
-
set(_, key, value) {
|
|
40
|
-
glint[key] = value;
|
|
41
|
-
return true;
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function installMethodLogging(logger, service) {
|
|
46
|
-
for (let _key in service) {
|
|
47
|
-
let key = _key;
|
|
48
|
-
let f = service[key];
|
|
49
|
-
if (typeof f === 'function') {
|
|
50
|
-
service[key] = ((...params) => {
|
|
51
|
-
logger.log(key, params[0]);
|
|
52
|
-
return f.apply(service, params);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
module.exports = init;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import VirtualModuleManager from './virtual-module-manager';
|
|
3
|
-
export default class GlintLanguageService implements Partial<ts.LanguageService> {
|
|
4
|
-
private readonly ts;
|
|
5
|
-
private readonly modules;
|
|
6
|
-
private readonly ls;
|
|
7
|
-
private readonly logger;
|
|
8
|
-
constructor(ts: typeof import('typescript/lib/tsserverlibrary'), modules: VirtualModuleManager, info: ts.server.PluginCreateInfo);
|
|
9
|
-
private getTransformInfoForOriginalPath;
|
|
10
|
-
private getTransformInfoForTransformedPath;
|
|
11
|
-
private getTransformInfo;
|
|
12
|
-
getSyntacticDiagnostics(fileName: string): ts.DiagnosticWithLocation[];
|
|
13
|
-
getSemanticDiagnostics(fileName: string): ts.Diagnostic[];
|
|
14
|
-
getSuggestionDiagnostics(fileName: string): ts.DiagnosticWithLocation[];
|
|
15
|
-
getEncodedSyntacticClassifications(fileName: string, span: ts.TextSpan): ts.Classifications;
|
|
16
|
-
getEncodedSemanticClassifications(fileName: string, span: ts.TextSpan): ts.Classifications;
|
|
17
|
-
getCompletionsAtPosition(fileName: string, offset: number, options: ts.GetCompletionsAtPositionOptions | undefined): ts.WithMetadata<ts.CompletionInfo> | undefined;
|
|
18
|
-
getCompletionEntryDetails(fileName: string, offset: number, name: string, formatOptions: ts.FormatCodeOptions | ts.FormatCodeSettings | undefined, source: string | undefined, preferences: ts.UserPreferences | undefined): ts.CompletionEntryDetails | undefined;
|
|
19
|
-
getCompletionEntrySymbol(fileName: string, offset: number, name: string, source: string | undefined): ts.Symbol | undefined;
|
|
20
|
-
getQuickInfoAtPosition(fileName: string, offset: number): ts.QuickInfo | undefined;
|
|
21
|
-
getRenameInfo(fileName: string, offset: number, options?: ts.RenameInfoOptions | undefined): ts.RenameInfo;
|
|
22
|
-
findRenameLocations(fileName: string, offset: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean | undefined): readonly ts.RenameLocation[] | undefined;
|
|
23
|
-
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences | undefined): readonly ts.FileTextChanges[];
|
|
24
|
-
getDefinitionAtPosition(fileName: string, offset: number): readonly ts.DefinitionInfo[] | undefined;
|
|
25
|
-
getDefinitionAndBoundSpan(fileName: string, offset: number): ts.DefinitionInfoAndBoundSpan | undefined;
|
|
26
|
-
getReferencesAtPosition(fileName: string, offset: number): ts.ReferenceEntry[] | undefined;
|
|
27
|
-
findReferences(fileName: string, offset: number): ts.ReferencedSymbol[] | undefined;
|
|
28
|
-
private rewriteDefinition;
|
|
29
|
-
private rewriteReferenceEntries;
|
|
30
|
-
private rewriteDocumentSpan;
|
|
31
|
-
private rewriteCodeAction;
|
|
32
|
-
}
|
package/lib/language-service.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const transform_1 = require("@glint/transform");
|
|
4
|
-
const logging_1 = require("./util/logging");
|
|
5
|
-
const path_transformation_1 = require("./util/path-transformation");
|
|
6
|
-
const auto_import_1 = require("./util/auto-import");
|
|
7
|
-
class GlintLanguageService {
|
|
8
|
-
constructor(ts, modules, info) {
|
|
9
|
-
this.ts = ts;
|
|
10
|
-
this.modules = modules;
|
|
11
|
-
this.ls = info.languageService;
|
|
12
|
-
this.logger = logging_1.loggerFor(info);
|
|
13
|
-
}
|
|
14
|
-
getTransformInfoForOriginalPath(originalPath) {
|
|
15
|
-
if (path_transformation_1.isTransformablePath(originalPath)) {
|
|
16
|
-
return this.getTransformInfo(originalPath, path_transformation_1.getTransformedPath(originalPath));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
getTransformInfoForTransformedPath(transformedPath) {
|
|
20
|
-
if (path_transformation_1.isTransformedPath(transformedPath)) {
|
|
21
|
-
return this.getTransformInfo(path_transformation_1.getOriginalPath(transformedPath), transformedPath);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
getTransformInfo(originalPath, transformedPath) {
|
|
25
|
-
var _a;
|
|
26
|
-
let transformedModule = this.modules.getTransformedModule(originalPath);
|
|
27
|
-
let transformedSourceFile = (_a = this.ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(transformedPath);
|
|
28
|
-
if (transformedModule && transformedSourceFile) {
|
|
29
|
-
return { transformedModule, transformedPath, transformedSourceFile, originalPath };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
getSyntacticDiagnostics(fileName) {
|
|
33
|
-
var _a, _b, _c;
|
|
34
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
35
|
-
let transformationErrors = (_b = (_a = info === null || info === void 0 ? void 0 : info.transformedModule) === null || _a === void 0 ? void 0 : _a.errors) !== null && _b !== void 0 ? _b : [];
|
|
36
|
-
let originalSourceFile = (_c = this.ls.getProgram()) === null || _c === void 0 ? void 0 : _c.getSourceFile(fileName);
|
|
37
|
-
return [
|
|
38
|
-
...this.ls.getSyntacticDiagnostics(fileName),
|
|
39
|
-
...transformationErrors.map((error) => ({
|
|
40
|
-
category: this.ts.DiagnosticCategory.Error,
|
|
41
|
-
code: 0,
|
|
42
|
-
file: originalSourceFile,
|
|
43
|
-
start: error.location.start,
|
|
44
|
-
length: error.location.end - error.location.start,
|
|
45
|
-
messageText: `[glint] ${error.message}`,
|
|
46
|
-
})),
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
getSemanticDiagnostics(fileName) {
|
|
50
|
-
var _a;
|
|
51
|
-
const info = this.getTransformInfoForOriginalPath(fileName);
|
|
52
|
-
const originalSourceFile = (_a = this.ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
53
|
-
if (info && originalSourceFile) {
|
|
54
|
-
return this.ls
|
|
55
|
-
.getSemanticDiagnostics(info.transformedPath)
|
|
56
|
-
.map((diagnostic) => transform_1.rewriteDiagnostic(diagnostic, info.transformedModule, originalSourceFile));
|
|
57
|
-
}
|
|
58
|
-
return this.ls.getSemanticDiagnostics(fileName);
|
|
59
|
-
}
|
|
60
|
-
getSuggestionDiagnostics(fileName) {
|
|
61
|
-
var _a;
|
|
62
|
-
const info = this.getTransformInfoForOriginalPath(fileName);
|
|
63
|
-
const originalSourceFile = (_a = this.ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
64
|
-
if (info && originalSourceFile) {
|
|
65
|
-
return this.ls
|
|
66
|
-
.getSuggestionDiagnostics(info.transformedPath)
|
|
67
|
-
.map((diagnostic) => transform_1.rewriteDiagnostic(diagnostic, info.transformedModule, originalSourceFile));
|
|
68
|
-
}
|
|
69
|
-
return this.ls.getSuggestionDiagnostics(fileName);
|
|
70
|
-
}
|
|
71
|
-
getEncodedSyntacticClassifications(fileName, span) {
|
|
72
|
-
return this.ls.getEncodedSyntacticClassifications(fileName, span);
|
|
73
|
-
}
|
|
74
|
-
getEncodedSemanticClassifications(fileName, span) {
|
|
75
|
-
return this.ls.getEncodedSemanticClassifications(fileName, span);
|
|
76
|
-
}
|
|
77
|
-
// Completions are only available in a small number of scenarios right now,
|
|
78
|
-
// because @glimmer/syntax has no error recovery/lax mode, and most of the
|
|
79
|
-
// time when you want a completion, you're not looking at valid template syntax.
|
|
80
|
-
// It _is_ useful for suggestion component args, though, and within a mustache
|
|
81
|
-
// or self-closing tag where you've _started_ typing, it can complete for you
|
|
82
|
-
// (though it's rare that you have perfect surrounding syntax in that scenario)
|
|
83
|
-
getCompletionsAtPosition(fileName, offset, options) {
|
|
84
|
-
var _a;
|
|
85
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
86
|
-
let result;
|
|
87
|
-
if (info) {
|
|
88
|
-
let range = info.transformedModule.getTransformedRange(offset, offset);
|
|
89
|
-
// If we're within a freeform text area in the template, don't attempt to autocomplete at all
|
|
90
|
-
let containingNode = (_a = range.mapping) === null || _a === void 0 ? void 0 : _a.sourceNode;
|
|
91
|
-
if (containingNode &&
|
|
92
|
-
['Template', 'Block', 'StringLiteral', 'ElementNode'].includes(containingNode.type)) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
result = this.ls.getCompletionsAtPosition(info.transformedPath, range.start, options);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
result = this.ls.getCompletionsAtPosition(fileName, offset, options);
|
|
99
|
-
}
|
|
100
|
-
if (!result)
|
|
101
|
-
return;
|
|
102
|
-
result = { ...result };
|
|
103
|
-
// Never show completions from transformed files
|
|
104
|
-
result.entries = result.entries.filter((entry) => !entry.source || !path_transformation_1.isExtensionlessTransformedPath(entry.source));
|
|
105
|
-
if (info) {
|
|
106
|
-
result.entries = result.entries.map((entry) => {
|
|
107
|
-
if (entry.replacementSpan) {
|
|
108
|
-
entry = { ...entry };
|
|
109
|
-
entry.replacementSpan = rewriteTextSpan(entry.replacementSpan, info.transformedModule);
|
|
110
|
-
}
|
|
111
|
-
return entry;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
getCompletionEntryDetails(fileName, offset, name, formatOptions, source, preferences) {
|
|
117
|
-
var _a;
|
|
118
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
119
|
-
if (info) {
|
|
120
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
121
|
-
let details = this.ls.getCompletionEntryDetails(info.transformedPath, transformedOffset, name, formatOptions, source, preferences);
|
|
122
|
-
if (details === null || details === void 0 ? void 0 : details.codeActions) {
|
|
123
|
-
details = {
|
|
124
|
-
...details,
|
|
125
|
-
codeActions: (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((action) => this.rewriteCodeAction(action)),
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
return details;
|
|
129
|
-
}
|
|
130
|
-
return this.ls.getCompletionEntryDetails(fileName, offset, name, formatOptions, source, preferences);
|
|
131
|
-
}
|
|
132
|
-
getCompletionEntrySymbol(fileName, offset, name, source) {
|
|
133
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
134
|
-
if (info) {
|
|
135
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
136
|
-
return this.ls.getCompletionEntrySymbol(info.transformedPath, transformedOffset, name, source);
|
|
137
|
-
}
|
|
138
|
-
return this.ls.getCompletionEntrySymbol(fileName, offset, name, source);
|
|
139
|
-
}
|
|
140
|
-
getQuickInfoAtPosition(fileName, offset) {
|
|
141
|
-
var _a;
|
|
142
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
143
|
-
let quickInfo;
|
|
144
|
-
if (info) {
|
|
145
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
146
|
-
quickInfo = this.ls.getQuickInfoAtPosition(info.transformedPath, transformedOffset);
|
|
147
|
-
if (quickInfo) {
|
|
148
|
-
quickInfo = { ...quickInfo };
|
|
149
|
-
quickInfo.textSpan = rewriteTextSpan(quickInfo.textSpan, info.transformedModule);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
quickInfo = this.ls.getQuickInfoAtPosition(fileName, offset);
|
|
154
|
-
}
|
|
155
|
-
if ((quickInfo === null || quickInfo === void 0 ? void 0 : quickInfo.kind) === 'module') {
|
|
156
|
-
// Ensures we display the non-transformed version of the resolved module
|
|
157
|
-
// path when getting quick info for an import source.
|
|
158
|
-
quickInfo.displayParts = (_a = quickInfo.displayParts) === null || _a === void 0 ? void 0 : _a.map((part) => {
|
|
159
|
-
if (part.kind === 'stringLiteral') {
|
|
160
|
-
return {
|
|
161
|
-
kind: 'stringLiteral',
|
|
162
|
-
text: rewriteQuotedModulePath(part.text),
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
return part;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
return quickInfo;
|
|
169
|
-
}
|
|
170
|
-
getRenameInfo(fileName, offset, options) {
|
|
171
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
172
|
-
if (info) {
|
|
173
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
174
|
-
let result = this.ls.getRenameInfo(info.transformedPath, transformedOffset, options);
|
|
175
|
-
if (result.canRename) {
|
|
176
|
-
result.triggerSpan = rewriteTextSpan(result.triggerSpan, info.transformedModule);
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
return this.ls.getRenameInfo(fileName, offset, options);
|
|
181
|
-
}
|
|
182
|
-
findRenameLocations(fileName, offset, findInStrings, findInComments, providePrefixAndSuffixTextForRename) {
|
|
183
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
184
|
-
let result;
|
|
185
|
-
if (info) {
|
|
186
|
-
result = this.ls.findRenameLocations(info.transformedPath, info.transformedModule.getTransformedOffset(offset), findInStrings, findInComments, providePrefixAndSuffixTextForRename);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
result = this.ls.findRenameLocations(fileName, offset, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
|
|
190
|
-
}
|
|
191
|
-
return result === null || result === void 0 ? void 0 : result.map((renameLocation) => {
|
|
192
|
-
renameLocation = this.rewriteDocumentSpan(renameLocation);
|
|
193
|
-
// Zero-length spans correspond to synthetic use (such as in the context type
|
|
194
|
-
// of the template, which references the containing class), so we want to filter
|
|
195
|
-
// those out.
|
|
196
|
-
if (!renameLocation.textSpan.length) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
return renameLocation;
|
|
200
|
-
}).filter((renameLocation) => !!renameLocation);
|
|
201
|
-
}
|
|
202
|
-
getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) {
|
|
203
|
-
let oldTransformedPath = path_transformation_1.isTransformablePath(oldFilePath)
|
|
204
|
-
? path_transformation_1.getTransformedPath(oldFilePath)
|
|
205
|
-
: oldFilePath;
|
|
206
|
-
let edits = [
|
|
207
|
-
...this.ls.getEditsForFileRename(oldTransformedPath, newFilePath, formatOptions, preferences),
|
|
208
|
-
...this.ls.getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences),
|
|
209
|
-
];
|
|
210
|
-
this.logger.log('getEditsForFileRename', oldTransformedPath, newFilePath, preferences, edits);
|
|
211
|
-
return edits.filter((edit) => !path_transformation_1.isTransformedPath(edit.fileName));
|
|
212
|
-
}
|
|
213
|
-
getDefinitionAtPosition(fileName, offset) {
|
|
214
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
215
|
-
let result;
|
|
216
|
-
if (info) {
|
|
217
|
-
let transformedPosition = info.transformedModule.getTransformedOffset(offset) + 1;
|
|
218
|
-
result = this.ls.getDefinitionAtPosition(info.transformedPath, transformedPosition);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
result = this.ls.getDefinitionAtPosition(fileName, offset);
|
|
222
|
-
}
|
|
223
|
-
result = result === null || result === void 0 ? void 0 : result.map((entry) => this.rewriteDefinition(entry));
|
|
224
|
-
this.logger.log('getDefinitionAtPosition', fileName, offset, result);
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
|
-
getDefinitionAndBoundSpan(fileName, offset) {
|
|
228
|
-
var _a;
|
|
229
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
230
|
-
let result;
|
|
231
|
-
if (info) {
|
|
232
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
233
|
-
result = this.ls.getDefinitionAndBoundSpan(info.transformedPath, transformedOffset);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
result = this.ls.getDefinitionAndBoundSpan(fileName, offset);
|
|
237
|
-
}
|
|
238
|
-
if (result) {
|
|
239
|
-
result = { ...result };
|
|
240
|
-
result.definitions = (_a = result.definitions) === null || _a === void 0 ? void 0 : _a.map((def) => this.rewriteDefinition(def));
|
|
241
|
-
if (info) {
|
|
242
|
-
result.textSpan = rewriteTextSpan(result.textSpan, info.transformedModule);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
getReferencesAtPosition(fileName, offset) {
|
|
248
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
249
|
-
if (info) {
|
|
250
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
251
|
-
let references = this.ls.getReferencesAtPosition(info.transformedPath, transformedOffset);
|
|
252
|
-
if (!references)
|
|
253
|
-
return;
|
|
254
|
-
return this.rewriteReferenceEntries(references);
|
|
255
|
-
}
|
|
256
|
-
return this.ls.getReferencesAtPosition(fileName, offset);
|
|
257
|
-
}
|
|
258
|
-
findReferences(fileName, offset) {
|
|
259
|
-
let info = this.getTransformInfoForOriginalPath(fileName);
|
|
260
|
-
if (info) {
|
|
261
|
-
let transformedOffset = info.transformedModule.getTransformedOffset(offset);
|
|
262
|
-
let references = this.ls.findReferences(info.transformedPath, transformedOffset);
|
|
263
|
-
if (!references)
|
|
264
|
-
return;
|
|
265
|
-
return references.map((ref) => {
|
|
266
|
-
ref = { ...ref };
|
|
267
|
-
ref.references = this.rewriteReferenceEntries(ref.references);
|
|
268
|
-
ref.definition = this.rewriteDefinition(ref.definition);
|
|
269
|
-
return ref;
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
return this.ls.findReferences(fileName, offset);
|
|
273
|
-
}
|
|
274
|
-
rewriteDefinition(def) {
|
|
275
|
-
let rewritten = this.rewriteDocumentSpan(def);
|
|
276
|
-
if (rewritten.kind === 'module') {
|
|
277
|
-
rewritten.name = rewriteQuotedModulePath(rewritten.name);
|
|
278
|
-
}
|
|
279
|
-
return rewritten;
|
|
280
|
-
}
|
|
281
|
-
rewriteReferenceEntries(entries) {
|
|
282
|
-
let referenceFiles = new Set(entries.map((ref) => ref.fileName));
|
|
283
|
-
return entries
|
|
284
|
-
.filter((ref) => {
|
|
285
|
-
// If we have references in both the transformed and untransformed version
|
|
286
|
-
// of a file, exclude any from the original, since that means the transformed
|
|
287
|
-
// module has at _least_ those references and possibly more. {}
|
|
288
|
-
return !(path_transformation_1.isTransformablePath(ref.fileName) && referenceFiles.has(path_transformation_1.getTransformedPath(ref.fileName)));
|
|
289
|
-
})
|
|
290
|
-
.map((ref) => this.rewriteDocumentSpan(ref))
|
|
291
|
-
.filter((ref) => {
|
|
292
|
-
// Any 0-length references are synthetic, and should be excluded
|
|
293
|
-
return ref.textSpan.length > 0;
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
rewriteDocumentSpan(documentSpan) {
|
|
297
|
-
let { fileName } = documentSpan;
|
|
298
|
-
if (path_transformation_1.isTransformedPath(fileName)) {
|
|
299
|
-
documentSpan = { ...documentSpan };
|
|
300
|
-
documentSpan.fileName = path_transformation_1.getOriginalPath(fileName);
|
|
301
|
-
}
|
|
302
|
-
let info = this.getTransformInfoForTransformedPath(fileName);
|
|
303
|
-
if (!info)
|
|
304
|
-
return documentSpan;
|
|
305
|
-
documentSpan.textSpan = rewriteTextSpan(documentSpan.textSpan, info.transformedModule);
|
|
306
|
-
if (documentSpan.contextSpan) {
|
|
307
|
-
documentSpan.contextSpan = rewriteTextSpan(documentSpan.contextSpan, info.transformedModule);
|
|
308
|
-
}
|
|
309
|
-
return documentSpan;
|
|
310
|
-
}
|
|
311
|
-
rewriteCodeAction(action) {
|
|
312
|
-
return {
|
|
313
|
-
...action,
|
|
314
|
-
changes: action.changes.map((change) => {
|
|
315
|
-
var _a;
|
|
316
|
-
change = { ...change };
|
|
317
|
-
if (path_transformation_1.isTransformedPath(change.fileName)) {
|
|
318
|
-
const changeInfo = this.getTransformInfoForTransformedPath(change.fileName);
|
|
319
|
-
if (changeInfo) {
|
|
320
|
-
change.fileName = changeInfo.originalPath;
|
|
321
|
-
change.textChanges = change.textChanges.map((textChange) => {
|
|
322
|
-
textChange = rewriteTextChange(this.ts, textChange, changeInfo.transformedSourceFile);
|
|
323
|
-
return {
|
|
324
|
-
...textChange,
|
|
325
|
-
span: rewriteTextSpan(textChange.span, changeInfo.transformedModule),
|
|
326
|
-
};
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
const sourceFile = (_a = this.ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(change.fileName);
|
|
332
|
-
if (sourceFile) {
|
|
333
|
-
change.textChanges = change.textChanges.map((textChange) => rewriteTextChange(this.ts, textChange, sourceFile));
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return change;
|
|
337
|
-
}),
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
exports.default = GlintLanguageService;
|
|
342
|
-
function rewriteTextChange(ts, textChange, sourceFile) {
|
|
343
|
-
if (auto_import_1.isAutoImportChange(textChange)) {
|
|
344
|
-
return auto_import_1.rewriteAutoImportChange(ts, textChange, sourceFile);
|
|
345
|
-
}
|
|
346
|
-
return textChange;
|
|
347
|
-
}
|
|
348
|
-
function rewriteTextSpan(span, module) {
|
|
349
|
-
if (!span)
|
|
350
|
-
return;
|
|
351
|
-
let originalRange = module.getOriginalRange(span.start, span.start + span.length);
|
|
352
|
-
return {
|
|
353
|
-
start: originalRange.start,
|
|
354
|
-
length: originalRange.end - originalRange.start,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
function rewriteQuotedModulePath(stringLiteral) {
|
|
358
|
-
let text = JSON.parse(stringLiteral);
|
|
359
|
-
if (path_transformation_1.isExtensionlessTransformedPath(text)) {
|
|
360
|
-
return `"${path_transformation_1.getExtensionlessOriginalPath(text)}"`;
|
|
361
|
-
}
|
|
362
|
-
return stringLiteral;
|
|
363
|
-
}
|
package/lib/logging.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare function loggerFor(info: ts.server.PluginCreateInfo): Logger;
|
|
2
|
-
export interface Logger {
|
|
3
|
-
readonly enabled: boolean;
|
|
4
|
-
log(...values: unknown[]): void;
|
|
5
|
-
}
|
|
6
|
-
export declare class FileLogger implements Logger {
|
|
7
|
-
private readonly logFile;
|
|
8
|
-
readonly enabled = true;
|
|
9
|
-
constructor(logFile: string);
|
|
10
|
-
log(...values: unknown[]): void;
|
|
11
|
-
}
|
package/lib/logging.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FileLogger = exports.loggerFor = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const LOGGERS = new WeakMap();
|
|
10
|
-
function loggerFor(info) {
|
|
11
|
-
let logger = LOGGERS.get(info);
|
|
12
|
-
if (!logger) {
|
|
13
|
-
let logFile = resolveLogFile(info);
|
|
14
|
-
if (logFile) {
|
|
15
|
-
fs_1.default.mkdirSync(path_1.default.dirname(logFile), { recursive: true });
|
|
16
|
-
logger = new FileLogger(logFile);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
logger = NOOP_LOGGER;
|
|
20
|
-
}
|
|
21
|
-
LOGGERS.set(info, logger);
|
|
22
|
-
}
|
|
23
|
-
return logger;
|
|
24
|
-
}
|
|
25
|
-
exports.loggerFor = loggerFor;
|
|
26
|
-
class FileLogger {
|
|
27
|
-
constructor(logFile) {
|
|
28
|
-
this.logFile = logFile;
|
|
29
|
-
this.enabled = true;
|
|
30
|
-
}
|
|
31
|
-
log(...values) {
|
|
32
|
-
fs_1.default.appendFileSync(this.logFile, stringToLog(values));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.FileLogger = FileLogger;
|
|
36
|
-
const NOOP_LOGGER = {
|
|
37
|
-
enabled: false,
|
|
38
|
-
log() {
|
|
39
|
-
// Do nothing
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
function resolveLogFile(info) {
|
|
43
|
-
let { logFile } = info.config;
|
|
44
|
-
if (typeof logFile === 'string') {
|
|
45
|
-
return path_1.default.resolve(path_1.default.dirname(info.project.projectName), logFile);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function stringToLog(values) {
|
|
49
|
-
return values.map(serialize).join(' ') + '\n';
|
|
50
|
-
}
|
|
51
|
-
function serialize(value) {
|
|
52
|
-
return typeof value === 'string' ? value : JSON.stringify(value, null, 2);
|
|
53
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { GlintConfig } from '@glint/config';
|
|
2
|
-
/**
|
|
3
|
-
* This patch updates module resolution logic on the language service host
|
|
4
|
-
* to cause imports to resolve to the transformed version of a given module
|
|
5
|
-
* rather than directly to the untransformed source.
|
|
6
|
-
*/
|
|
7
|
-
export declare function patchLanguageServiceHost(config: GlintConfig, { languageServiceHost }: ts.server.PluginCreateInfo): void;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patchLanguageServiceHost = void 0;
|
|
4
|
-
const path_transformation_1 = require("../util/path-transformation");
|
|
5
|
-
const hostConfigs = new WeakMap();
|
|
6
|
-
/**
|
|
7
|
-
* This patch updates module resolution logic on the language service host
|
|
8
|
-
* to cause imports to resolve to the transformed version of a given module
|
|
9
|
-
* rather than directly to the untransformed source.
|
|
10
|
-
*/
|
|
11
|
-
function patchLanguageServiceHost(config, { languageServiceHost }) {
|
|
12
|
-
let configs = hostConfigs.get(languageServiceHost);
|
|
13
|
-
if (configs) {
|
|
14
|
-
configs.add(config);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
hostConfigs.set(languageServiceHost, new Set([config]));
|
|
18
|
-
patchModuleResolution(languageServiceHost);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.patchLanguageServiceHost = patchLanguageServiceHost;
|
|
22
|
-
function patchModuleResolution(languageServiceHost) {
|
|
23
|
-
let { resolveModuleNames } = languageServiceHost;
|
|
24
|
-
languageServiceHost.resolveModuleNames = (moduleNames, containingFile, ...params) => {
|
|
25
|
-
var _a;
|
|
26
|
-
let result = (_a = resolveModuleNames === null || resolveModuleNames === void 0 ? void 0 : resolveModuleNames.call(languageServiceHost, moduleNames, containingFile, ...params)) !== null && _a !== void 0 ? _a : [];
|
|
27
|
-
return result.map((resolved) => {
|
|
28
|
-
if ((resolved === null || resolved === void 0 ? void 0 : resolved.resolvedFileName) === containingFile && path_transformation_1.isTransformedPath(containingFile)) {
|
|
29
|
-
// If we're in a transformed file and resolving its import of
|
|
30
|
-
// the original module, ensure that resolves to the actual module.
|
|
31
|
-
resolved = {
|
|
32
|
-
...resolved,
|
|
33
|
-
resolvedFileName: path_transformation_1.getOriginalPath(containingFile),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
else if (resolved &&
|
|
37
|
-
path_transformation_1.isTransformablePath(resolved.resolvedFileName) &&
|
|
38
|
-
isIncludedInConfig(languageServiceHost, resolved.resolvedFileName)) {
|
|
39
|
-
// Otherwise, point it to the transformed module, which will itself
|
|
40
|
-
// depend on and re-export items from the original if necessary.
|
|
41
|
-
let updated = path_transformation_1.getTransformedPath(resolved.resolvedFileName);
|
|
42
|
-
if (updated !== containingFile) {
|
|
43
|
-
resolved = { ...resolved, resolvedFileName: updated };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return resolved;
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function isIncludedInConfig(languageServiceHost, fileName) {
|
|
51
|
-
let configs = hostConfigs.get(languageServiceHost);
|
|
52
|
-
if (!configs)
|
|
53
|
-
return false;
|
|
54
|
-
for (let config of configs) {
|
|
55
|
-
if (config.includesFile(fileName)) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
package/lib/patch/lib.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type tslib from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import VirtualModuleManager from '../virtual-module-manager';
|
|
3
|
-
/**
|
|
4
|
-
* This module houses our deepest sins. Here we directly patch certain
|
|
5
|
-
* functions and class methods from `tsserverlibrary` in order to ensure
|
|
6
|
-
* we can properly manage two parallel versions of the world: one with
|
|
7
|
-
* the actual source text as provided by the editor, and one with the
|
|
8
|
-
* version we wish to present diagnostics for.
|
|
9
|
-
*/
|
|
10
|
-
export declare function patchLib(ts: typeof tslib, modules: VirtualModuleManager): void;
|
package/lib/patch/lib.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patchLib = void 0;
|
|
4
|
-
const path_transformation_1 = require("../util/path-transformation");
|
|
5
|
-
/**
|
|
6
|
-
* This module houses our deepest sins. Here we directly patch certain
|
|
7
|
-
* functions and class methods from `tsserverlibrary` in order to ensure
|
|
8
|
-
* we can properly manage two parallel versions of the world: one with
|
|
9
|
-
* the actual source text as provided by the editor, and one with the
|
|
10
|
-
* version we wish to present diagnostics for.
|
|
11
|
-
*/
|
|
12
|
-
function patchLib(ts, modules) {
|
|
13
|
-
patchFSOperations(ts, modules);
|
|
14
|
-
patchSourceFileCreation(ts, modules);
|
|
15
|
-
patchScriptInfo(ts);
|
|
16
|
-
}
|
|
17
|
-
exports.patchLib = patchLib;
|
|
18
|
-
function patchFSOperations(ts, modules) {
|
|
19
|
-
const { fileExists, watchFile } = ts.sys;
|
|
20
|
-
// Reroute existence checks for transformed modules back to their source
|
|
21
|
-
ts.sys.fileExists = (file) => {
|
|
22
|
-
if (path_transformation_1.isTransformedPath(file)) {
|
|
23
|
-
file = path_transformation_1.getOriginalPath(file);
|
|
24
|
-
}
|
|
25
|
-
return fileExists(file);
|
|
26
|
-
};
|
|
27
|
-
// Route file reading through the virtual module manager in order to
|
|
28
|
-
// present the transformed version of modules with templates in them,
|
|
29
|
-
// when appropriate.
|
|
30
|
-
ts.sys.readFile = (file, encoding) => {
|
|
31
|
-
return modules.readFile(file, encoding);
|
|
32
|
-
};
|
|
33
|
-
// Treat watch calls on virtual (transformed) modules as no-ops
|
|
34
|
-
ts.sys.watchFile = (file, callback, pollingInterval, options) => {
|
|
35
|
-
if (path_transformation_1.isTransformedPath(file) || !watchFile) {
|
|
36
|
-
return { close: () => { } };
|
|
37
|
-
}
|
|
38
|
-
return watchFile(file, callback, pollingInterval, options);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// Ensure after creation and update that any source file implicitly
|
|
42
|
-
// references its transformed version, if appropriate, so that the
|
|
43
|
-
// transformed version will be included in typechecking and can generate
|
|
44
|
-
// approprate diagnostics even if it's never explicitly imported.
|
|
45
|
-
function patchSourceFileCreation(ts, modules) {
|
|
46
|
-
const { createSourceFile, updateSourceFile } = ts;
|
|
47
|
-
ts.createSourceFile = (fileName, ...params) => {
|
|
48
|
-
let sourceFile = createSourceFile.call(ts, fileName, ...params);
|
|
49
|
-
if (modules.isTransformationCandidate(sourceFile.fileName)) {
|
|
50
|
-
addReferenceToTransformedFile(sourceFile);
|
|
51
|
-
}
|
|
52
|
-
return sourceFile;
|
|
53
|
-
};
|
|
54
|
-
ts.updateSourceFile = (sourceFile, ...params) => {
|
|
55
|
-
let updated = updateSourceFile(sourceFile, ...params);
|
|
56
|
-
if (modules.isTransformationCandidate(updated.fileName)) {
|
|
57
|
-
addReferenceToTransformedFile(updated);
|
|
58
|
-
}
|
|
59
|
-
return updated;
|
|
60
|
-
};
|
|
61
|
-
function addReferenceToTransformedFile(sourceFile) {
|
|
62
|
-
let referencedFiles = sourceFile.referencedFiles.slice();
|
|
63
|
-
if (path_transformation_1.isTransformablePath(sourceFile.fileName)) {
|
|
64
|
-
referencedFiles.push({
|
|
65
|
-
fileName: path_transformation_1.getTransformedPath(sourceFile.fileName),
|
|
66
|
-
pos: sourceFile.text.length,
|
|
67
|
-
end: sourceFile.text.length,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
sourceFile.referencedFiles = referencedFiles;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Ensure that any update to a module, either on disk or in-memory in
|
|
74
|
-
// the editor, also triggers an update to its transformed counterpart.
|
|
75
|
-
function patchScriptInfo(ts) {
|
|
76
|
-
const { ScriptInfo } = ts.server;
|
|
77
|
-
const { registerFileUpdate, editContent } = ScriptInfo.prototype;
|
|
78
|
-
ScriptInfo.prototype.registerFileUpdate = function () {
|
|
79
|
-
var _a;
|
|
80
|
-
registerFileUpdate.call(this);
|
|
81
|
-
(_a = findTransformedScriptInfo(this)) === null || _a === void 0 ? void 0 : _a.registerFileUpdate();
|
|
82
|
-
};
|
|
83
|
-
ScriptInfo.prototype.editContent = function (start, end, newText) {
|
|
84
|
-
editContent.call(this, start, end, newText);
|
|
85
|
-
let transformedInfo = findTransformedScriptInfo(this);
|
|
86
|
-
transformedInfo === null || transformedInfo === void 0 ? void 0 : transformedInfo.registerFileUpdate();
|
|
87
|
-
transformedInfo === null || transformedInfo === void 0 ? void 0 : transformedInfo.reloadFromFile();
|
|
88
|
-
};
|
|
89
|
-
function findTransformedScriptInfo(original) {
|
|
90
|
-
let { fileName } = original;
|
|
91
|
-
if (!path_transformation_1.isTransformablePath(fileName))
|
|
92
|
-
return;
|
|
93
|
-
let transformedFileName = path_transformation_1.getTransformedPath(fileName);
|
|
94
|
-
for (let project of original.containingProjects) {
|
|
95
|
-
let info = project.getScriptInfo(transformedFileName);
|
|
96
|
-
if (info) {
|
|
97
|
-
return info;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare const TRANSFORMED: unique symbol;
|
|
2
|
-
declare const TRANSFORMABLE: unique symbol;
|
|
3
|
-
export declare type TransformedPath = string & {
|
|
4
|
-
[TRANSFORMED]: true;
|
|
5
|
-
};
|
|
6
|
-
export declare type TransformablePath = string & {
|
|
7
|
-
[TRANSFORMABLE]: true;
|
|
8
|
-
};
|
|
9
|
-
export declare function getTransformedPath(path: TransformablePath): TransformedPath;
|
|
10
|
-
export declare function getOriginalPath(path: TransformedPath): TransformablePath;
|
|
11
|
-
export declare function isTransformablePath(path: string): path is TransformablePath;
|
|
12
|
-
export declare function isTransformedPath(path: string): path is TransformedPath;
|
|
13
|
-
export declare function isExtensionlessTransformedPath(path: string): boolean;
|
|
14
|
-
export declare function getExtensionlessOriginalPath(path: string): string;
|
|
15
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExtensionlessOriginalPath = exports.isExtensionlessTransformedPath = exports.isTransformedPath = exports.isTransformablePath = exports.getOriginalPath = exports.getTransformedPath = void 0;
|
|
4
|
-
const EXTENSIONLESS_TRANSFORMED_SUFFIX = '❈';
|
|
5
|
-
const TRANSFORMED_SUFFIX = `${EXTENSIONLESS_TRANSFORMED_SUFFIX}.ts`;
|
|
6
|
-
function getTransformedPath(path) {
|
|
7
|
-
return path.replace('.ts', TRANSFORMED_SUFFIX);
|
|
8
|
-
}
|
|
9
|
-
exports.getTransformedPath = getTransformedPath;
|
|
10
|
-
function getOriginalPath(path) {
|
|
11
|
-
return path.replace(TRANSFORMED_SUFFIX, '.ts');
|
|
12
|
-
}
|
|
13
|
-
exports.getOriginalPath = getOriginalPath;
|
|
14
|
-
function isTransformablePath(path) {
|
|
15
|
-
return path.endsWith('.ts') && !path.endsWith('.d.ts') && !path.endsWith(TRANSFORMED_SUFFIX);
|
|
16
|
-
}
|
|
17
|
-
exports.isTransformablePath = isTransformablePath;
|
|
18
|
-
function isTransformedPath(path) {
|
|
19
|
-
return path.endsWith(TRANSFORMED_SUFFIX);
|
|
20
|
-
}
|
|
21
|
-
exports.isTransformedPath = isTransformedPath;
|
|
22
|
-
// When dealing with modules, paths often don't include the extension...
|
|
23
|
-
function isExtensionlessTransformedPath(path) {
|
|
24
|
-
return path.endsWith(EXTENSIONLESS_TRANSFORMED_SUFFIX);
|
|
25
|
-
}
|
|
26
|
-
exports.isExtensionlessTransformedPath = isExtensionlessTransformedPath;
|
|
27
|
-
function getExtensionlessOriginalPath(path) {
|
|
28
|
-
return path.replace(EXTENSIONLESS_TRANSFORMED_SUFFIX, '');
|
|
29
|
-
}
|
|
30
|
-
exports.getExtensionlessOriginalPath = getExtensionlessOriginalPath;
|
package/lib/util/auto-import.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rewriteAutoImportChange = exports.isAutoImportChange = void 0;
|
|
4
|
-
function isAutoImportChange(change) {
|
|
5
|
-
return change.newText.startsWith('import');
|
|
6
|
-
}
|
|
7
|
-
exports.isAutoImportChange = isAutoImportChange;
|
|
8
|
-
function rewriteAutoImportChange(ts, change, sourceFile) {
|
|
9
|
-
let importPath = getImportPath(ts, change.newText);
|
|
10
|
-
if (!importPath)
|
|
11
|
-
return change;
|
|
12
|
-
let existingImport = findExistingImport(ts, importPath, sourceFile);
|
|
13
|
-
if (!existingImport)
|
|
14
|
-
return change;
|
|
15
|
-
let combinedImport = synthesizeCombinedImport(ts, existingImport.text, change.newText);
|
|
16
|
-
if (!combinedImport)
|
|
17
|
-
return change;
|
|
18
|
-
return {
|
|
19
|
-
newText: combinedImport,
|
|
20
|
-
span: existingImport.span,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
exports.rewriteAutoImportChange = rewriteAutoImportChange;
|
|
24
|
-
function findExistingImport(ts, path, sourceFile) {
|
|
25
|
-
let importDeclaration = sourceFile.statements.find((statement) => {
|
|
26
|
-
return (ts.isImportDeclaration(statement) &&
|
|
27
|
-
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
28
|
-
statement.moduleSpecifier.text === path);
|
|
29
|
-
});
|
|
30
|
-
if (importDeclaration) {
|
|
31
|
-
let text = importDeclaration.getText(sourceFile);
|
|
32
|
-
let start = importDeclaration.getStart(sourceFile);
|
|
33
|
-
let length = importDeclaration.getEnd() - start;
|
|
34
|
-
return { text, span: { start, length } };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function getImportPath(ts, text) {
|
|
38
|
-
try {
|
|
39
|
-
let file = ts.createSourceFile('import.ts', text, ts.ScriptTarget.Latest);
|
|
40
|
-
if (file.statements.length === 1) {
|
|
41
|
-
let statement = file.statements[0];
|
|
42
|
-
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
43
|
-
return statement.moduleSpecifier.text;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
// Fall through and return undefined
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function synthesizeCombinedImport(ts, oldImportText, newImportText) {
|
|
52
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
53
|
-
let parsed = parseImportsTogether(ts, oldImportText, newImportText);
|
|
54
|
-
if (!parsed)
|
|
55
|
-
return;
|
|
56
|
-
let { oldImport, newImport, sourceFile } = parsed;
|
|
57
|
-
let newName = (_a = newImport.importClause) === null || _a === void 0 ? void 0 : _a.name;
|
|
58
|
-
let oldName = (_b = oldImport.importClause) === null || _b === void 0 ? void 0 : _b.name;
|
|
59
|
-
let name;
|
|
60
|
-
if (!newName || !oldName) {
|
|
61
|
-
name = newName !== null && newName !== void 0 ? newName : oldName;
|
|
62
|
-
}
|
|
63
|
-
else if ((newName === null || newName === void 0 ? void 0 : newName.text) === (oldName === null || oldName === void 0 ? void 0 : oldName.text)) {
|
|
64
|
-
name = newName;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
let newBindings = (_c = newImport.importClause) === null || _c === void 0 ? void 0 : _c.namedBindings;
|
|
70
|
-
let oldBindings = (_d = oldImport.importClause) === null || _d === void 0 ? void 0 : _d.namedBindings;
|
|
71
|
-
let bindings;
|
|
72
|
-
if (!oldBindings || !newBindings) {
|
|
73
|
-
bindings = newBindings !== null && newBindings !== void 0 ? newBindings : oldBindings;
|
|
74
|
-
}
|
|
75
|
-
else if (ts.isNamedImports(oldBindings) && ts.isNamedImports(newBindings)) {
|
|
76
|
-
bindings = ts.createNamedImports([
|
|
77
|
-
...((_e = oldBindings === null || oldBindings === void 0 ? void 0 : oldBindings.elements) !== null && _e !== void 0 ? _e : []),
|
|
78
|
-
...((_f = newBindings === null || newBindings === void 0 ? void 0 : newBindings.elements) !== null && _f !== void 0 ? _f : []),
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
else if (ts.isNamespaceImport(oldBindings) && ts.isNamespaceImport(newBindings)) {
|
|
82
|
-
if ((oldBindings === null || oldBindings === void 0 ? void 0 : oldBindings.name.text) !== (newBindings === null || newBindings === void 0 ? void 0 : newBindings.name.text)) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
bindings = oldBindings;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
let combinedImport = ts.createImportDeclaration(oldImport.decorators, oldImport.modifiers, ts.createImportClause(name, bindings, ((_g = oldImport.importClause) === null || _g === void 0 ? void 0 : _g.isTypeOnly) && ((_h = newImport.importClause) === null || _h === void 0 ? void 0 : _h.isTypeOnly)), oldImport.moduleSpecifier);
|
|
93
|
-
let result = ts.createPrinter().printNode(ts.EmitHint.Unspecified, combinedImport, sourceFile);
|
|
94
|
-
if (/'/.test(oldImportText)) {
|
|
95
|
-
result = result.replace(/"/g, `'`);
|
|
96
|
-
}
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
function parseImportsTogether(ts, oldImportText, newImportText) {
|
|
100
|
-
let sourceFile = ts.createSourceFile('tmp.ts', `${oldImportText}\n${newImportText}`, ts.ScriptTarget.Latest);
|
|
101
|
-
let [oldImport, newImport] = sourceFile.statements;
|
|
102
|
-
if (ts.isImportDeclaration(oldImport) && ts.isImportDeclaration(newImport)) {
|
|
103
|
-
return { oldImport, newImport, sourceFile };
|
|
104
|
-
}
|
|
105
|
-
}
|
package/lib/util/logging.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare function loggerFor(info: ts.server.PluginCreateInfo): Logger;
|
|
2
|
-
export interface Logger {
|
|
3
|
-
readonly enabled: boolean;
|
|
4
|
-
log(...values: unknown[]): void;
|
|
5
|
-
}
|
|
6
|
-
export declare class FileLogger implements Logger {
|
|
7
|
-
private readonly logFile;
|
|
8
|
-
readonly enabled = true;
|
|
9
|
-
constructor(logFile: string);
|
|
10
|
-
log(...values: unknown[]): void;
|
|
11
|
-
}
|
package/lib/util/logging.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FileLogger = exports.loggerFor = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const LOGGERS = new WeakMap();
|
|
10
|
-
function loggerFor(info) {
|
|
11
|
-
let logger = LOGGERS.get(info);
|
|
12
|
-
if (!logger) {
|
|
13
|
-
let logFile = resolveLogFile(info);
|
|
14
|
-
if (logFile) {
|
|
15
|
-
fs_1.default.mkdirSync(path_1.default.dirname(logFile), { recursive: true });
|
|
16
|
-
logger = new FileLogger(logFile);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
logger = NOOP_LOGGER;
|
|
20
|
-
}
|
|
21
|
-
LOGGERS.set(info, logger);
|
|
22
|
-
}
|
|
23
|
-
return logger;
|
|
24
|
-
}
|
|
25
|
-
exports.loggerFor = loggerFor;
|
|
26
|
-
class FileLogger {
|
|
27
|
-
constructor(logFile) {
|
|
28
|
-
this.logFile = logFile;
|
|
29
|
-
this.enabled = true;
|
|
30
|
-
}
|
|
31
|
-
log(...values) {
|
|
32
|
-
fs_1.default.appendFileSync(this.logFile, stringToLog(values));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.FileLogger = FileLogger;
|
|
36
|
-
const NOOP_LOGGER = {
|
|
37
|
-
enabled: false,
|
|
38
|
-
log() {
|
|
39
|
-
// Do nothing
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
function resolveLogFile(info) {
|
|
43
|
-
let { logFile } = info.config;
|
|
44
|
-
if (typeof logFile === 'string') {
|
|
45
|
-
return path_1.default.resolve(path_1.default.dirname(info.project.projectName), logFile);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function stringToLog(values) {
|
|
49
|
-
return values.map(serialize).join(' ') + '\n';
|
|
50
|
-
}
|
|
51
|
-
function serialize(value) {
|
|
52
|
-
return typeof value === 'string' ? value : JSON.stringify(value, null, 2);
|
|
53
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare const TRANSFORMED: unique symbol;
|
|
2
|
-
declare const TRANSFORMABLE: unique symbol;
|
|
3
|
-
export declare type TransformedPath = string & {
|
|
4
|
-
[TRANSFORMED]: true;
|
|
5
|
-
};
|
|
6
|
-
export declare type TransformablePath = string & {
|
|
7
|
-
[TRANSFORMABLE]: true;
|
|
8
|
-
};
|
|
9
|
-
export declare function getTransformedPath(path: TransformablePath): TransformedPath;
|
|
10
|
-
export declare function getOriginalPath(path: TransformedPath): TransformablePath;
|
|
11
|
-
export declare function isTransformablePath(path: string): path is TransformablePath;
|
|
12
|
-
export declare function isTransformedPath(path: string): path is TransformedPath;
|
|
13
|
-
export declare function isExtensionlessTransformedPath(path: string): boolean;
|
|
14
|
-
export declare function getExtensionlessOriginalPath(path: string): string;
|
|
15
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExtensionlessOriginalPath = exports.isExtensionlessTransformedPath = exports.isTransformedPath = exports.isTransformablePath = exports.getOriginalPath = exports.getTransformedPath = void 0;
|
|
4
|
-
const EXTENSIONLESS_TRANSFORMED_SUFFIX = '❈';
|
|
5
|
-
const TRANSFORMED_SUFFIX = `${EXTENSIONLESS_TRANSFORMED_SUFFIX}.ts`;
|
|
6
|
-
function getTransformedPath(path) {
|
|
7
|
-
return path.replace('.ts', TRANSFORMED_SUFFIX);
|
|
8
|
-
}
|
|
9
|
-
exports.getTransformedPath = getTransformedPath;
|
|
10
|
-
function getOriginalPath(path) {
|
|
11
|
-
return path.replace(TRANSFORMED_SUFFIX, '.ts');
|
|
12
|
-
}
|
|
13
|
-
exports.getOriginalPath = getOriginalPath;
|
|
14
|
-
function isTransformablePath(path) {
|
|
15
|
-
return path.endsWith('.ts') && !path.endsWith('.d.ts') && !path.endsWith(TRANSFORMED_SUFFIX);
|
|
16
|
-
}
|
|
17
|
-
exports.isTransformablePath = isTransformablePath;
|
|
18
|
-
function isTransformedPath(path) {
|
|
19
|
-
return path.endsWith(TRANSFORMED_SUFFIX);
|
|
20
|
-
}
|
|
21
|
-
exports.isTransformedPath = isTransformedPath;
|
|
22
|
-
// When dealing with modules, paths often don't include the extension...
|
|
23
|
-
function isExtensionlessTransformedPath(path) {
|
|
24
|
-
return path.endsWith(EXTENSIONLESS_TRANSFORMED_SUFFIX);
|
|
25
|
-
}
|
|
26
|
-
exports.isExtensionlessTransformedPath = isExtensionlessTransformedPath;
|
|
27
|
-
function getExtensionlessOriginalPath(path) {
|
|
28
|
-
return path.replace(EXTENSIONLESS_TRANSFORMED_SUFFIX, '');
|
|
29
|
-
}
|
|
30
|
-
exports.getExtensionlessOriginalPath = getExtensionlessOriginalPath;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import { TransformedModule } from '@glint/transform';
|
|
3
|
-
import { TransformablePath } from './util/path-transformation';
|
|
4
|
-
import { GlintConfig } from '@glint/config';
|
|
5
|
-
export default class VirtualModuleManager {
|
|
6
|
-
private configuredProjects;
|
|
7
|
-
private transformedModules;
|
|
8
|
-
private sysReadFile;
|
|
9
|
-
constructor(ts: typeof import('typescript/lib/tsserverlibrary'));
|
|
10
|
-
addProject(config: GlintConfig, project: ts.server.Project): void;
|
|
11
|
-
isTransformationCandidate(path: string): boolean;
|
|
12
|
-
getTransformedModule(path: TransformablePath): TransformedModule | undefined;
|
|
13
|
-
readFile(path: string, encoding?: string): string | undefined;
|
|
14
|
-
private findConfiguredProject;
|
|
15
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const transform_1 = require("@glint/transform");
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const path_transformation_1 = require("./util/path-transformation");
|
|
6
|
-
class VirtualModuleManager {
|
|
7
|
-
constructor(ts) {
|
|
8
|
-
this.configuredProjects = [];
|
|
9
|
-
this.transformedModules = new Map();
|
|
10
|
-
this.sysReadFile = ts.sys.readFile;
|
|
11
|
-
}
|
|
12
|
-
addProject(config, project) {
|
|
13
|
-
this.configuredProjects.push({ project, config });
|
|
14
|
-
}
|
|
15
|
-
isTransformationCandidate(path) {
|
|
16
|
-
return Boolean(this.findConfiguredProject(path));
|
|
17
|
-
}
|
|
18
|
-
getTransformedModule(path) {
|
|
19
|
-
var _a;
|
|
20
|
-
let scriptInfo = (_a = this.findConfiguredProject(path)) === null || _a === void 0 ? void 0 : _a.project.getScriptInfo(path);
|
|
21
|
-
return scriptInfo && this.transformedModules.get(scriptInfo);
|
|
22
|
-
}
|
|
23
|
-
readFile(path, encoding) {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
if (!path_transformation_1.isTransformedPath(path)) {
|
|
26
|
-
return this.sysReadFile(path, encoding);
|
|
27
|
-
}
|
|
28
|
-
let configuredProject = this.findConfiguredProject(path);
|
|
29
|
-
if (!configuredProject) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
let originalPath = path_transformation_1.getOriginalPath(path);
|
|
33
|
-
let originalScriptInfo = configuredProject.project.getScriptInfo(originalPath);
|
|
34
|
-
let glintEnvironment = configuredProject.config.environment;
|
|
35
|
-
let snapshot = originalScriptInfo === null || originalScriptInfo === void 0 ? void 0 : originalScriptInfo.getSnapshot();
|
|
36
|
-
let length = (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.getLength()) !== null && _a !== void 0 ? _a : 0;
|
|
37
|
-
let content = (_b = snapshot === null || snapshot === void 0 ? void 0 : snapshot.getText(0, length)) !== null && _b !== void 0 ? _b : this.sysReadFile(originalPath, encoding);
|
|
38
|
-
if (!content || !glintEnvironment.moduleMayHaveTagImports(content)) {
|
|
39
|
-
return content;
|
|
40
|
-
}
|
|
41
|
-
let transformedModule = transform_1.rewriteModule(originalPath, content, glintEnvironment);
|
|
42
|
-
if (transformedModule && originalScriptInfo) {
|
|
43
|
-
this.transformedModules.set(originalScriptInfo, transformedModule);
|
|
44
|
-
return transformedModule.transformedSource;
|
|
45
|
-
}
|
|
46
|
-
if (originalScriptInfo) {
|
|
47
|
-
this.transformedModules.delete(originalScriptInfo);
|
|
48
|
-
}
|
|
49
|
-
let originalModuleName = path_1.basename(originalPath, '.ts');
|
|
50
|
-
let exports = [`export * from './${originalModuleName}';`];
|
|
51
|
-
// This is far from perfect detection, but it's a reasonable approximation
|
|
52
|
-
// and the consequences of a false positive are minimal. This avoids needing
|
|
53
|
-
// to parse the entire module to discover whether there's a default export.
|
|
54
|
-
if (/export(\s+|\s*\{\s*)default/.test(content)) {
|
|
55
|
-
exports.push(`export { default } from './${originalModuleName}';`);
|
|
56
|
-
}
|
|
57
|
-
return exports.join('\n');
|
|
58
|
-
}
|
|
59
|
-
findConfiguredProject(fileName) {
|
|
60
|
-
for (let project of this.configuredProjects) {
|
|
61
|
-
if (project.config.includesFile(fileName)) {
|
|
62
|
-
return project;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.default = VirtualModuleManager;
|