@nexus-ioc/language-service 0.1.0
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/LICENSE +21 -0
- package/README.md +134 -0
- package/dist/actions/get-completion-info.actions.d.ts +3 -0
- package/dist/actions/get-completion-info.actions.js +57 -0
- package/dist/actions/get-completion-info.actions.js.map +1 -0
- package/dist/actions/get-semantic-diagnostics.actions.d.ts +3 -0
- package/dist/actions/get-semantic-diagnostics.actions.js +153 -0
- package/dist/actions/get-semantic-diagnostics.actions.js.map +1 -0
- package/dist/helpers/check-types.helper.d.ts +3 -0
- package/dist/helpers/check-types.helper.js +30 -0
- package/dist/helpers/check-types.helper.js.map +1 -0
- package/dist/helpers/compare-string-types.helper.d.ts +4 -0
- package/dist/helpers/compare-string-types.helper.js +16 -0
- package/dist/helpers/compare-string-types.helper.js.map +1 -0
- package/dist/helpers/find-node-at-position.helper.d.ts +2 -0
- package/dist/helpers/find-node-at-position.helper.js +16 -0
- package/dist/helpers/find-node-at-position.helper.js.map +1 -0
- package/dist/helpers/find-type-references.helper.d.ts +8 -0
- package/dist/helpers/find-type-references.helper.js +51 -0
- package/dist/helpers/find-type-references.helper.js.map +1 -0
- package/dist/helpers/get-type-of-node.helper.d.ts +2 -0
- package/dist/helpers/get-type-of-node.helper.js +14 -0
- package/dist/helpers/get-type-of-node.helper.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/language-service/ns-language-service.d.ts +19 -0
- package/dist/language-service/ns-language-service.js +33 -0
- package/dist/language-service/ns-language-service.js.map +1 -0
- package/dist/language-service/parse-config-service.d.ts +22 -0
- package/dist/language-service/parse-config-service.js +61 -0
- package/dist/language-service/parse-config-service.js.map +1 -0
- package/dist/language-service/types.d.ts +88 -0
- package/dist/language-service/types.js +3 -0
- package/dist/language-service/types.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +19 -0
- package/dist/logger.js.map +1 -0
- package/dist/parsers/inject.parser.d.ts +16 -0
- package/dist/parsers/inject.parser.js +44 -0
- package/dist/parsers/inject.parser.js.map +1 -0
- package/dist/parsers/injectable.parser.d.ts +5 -0
- package/dist/parsers/injectable.parser.js +13 -0
- package/dist/parsers/injectable.parser.js.map +1 -0
- package/dist/parsers/ns-module.parser.d.ts +45 -0
- package/dist/parsers/ns-module.parser.js +237 -0
- package/dist/parsers/ns-module.parser.js.map +1 -0
- package/dist/parsers/ns-modules.parser.d.ts +7 -0
- package/dist/parsers/ns-modules.parser.js +35 -0
- package/dist/parsers/ns-modules.parser.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Aleksandr Melnik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Nexus IoC is a powerful and flexible Inversion of Control (IoC) container for TypeScript applications. Inspired by Angular and NestJS, it leverages decorators to provide a simple and efficient way to manage dependencies and modules.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Features](#features)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Quick Start](#quick-start)
|
|
12
|
+
- [Testing](#testing)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
- [Author](#author)
|
|
15
|
+
- [Contributing](#contributing)
|
|
16
|
+
- [Acknowledgements](#acknowledgements)
|
|
17
|
+
- [Wiki](#wiki)
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **Modular Architecture**: Easily create and manage modules.
|
|
22
|
+
- **Dependency Injection**: Use decorators to inject dependencies into your classes.
|
|
23
|
+
- **Lifecycle Management**: Manage the lifecycle of your components seamlessly.
|
|
24
|
+
- **Asynchronous Module Loading**: Load modules asynchronously for improved performance.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @nexus-ioc/core reflect-metadata
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Step 1: Define Your Modules and Providers
|
|
35
|
+
|
|
36
|
+
Create a module and a provider using decorators.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { NsModule, Injectable, Inject } from '@nexus-ioc/core';
|
|
40
|
+
|
|
41
|
+
@Injectable()
|
|
42
|
+
class DependencyService {
|
|
43
|
+
public readonly name = 'World';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Injectable()
|
|
47
|
+
export class AppService {
|
|
48
|
+
constructor(
|
|
49
|
+
@Inject(DependencyService)
|
|
50
|
+
private readonly dependencyService: DependencyService,
|
|
51
|
+
) {
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getHello(): string {
|
|
55
|
+
return `Hello ${this.dependencyService.name}!`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@NsModule({
|
|
60
|
+
providers: [AppService, DependencyService],
|
|
61
|
+
})
|
|
62
|
+
export class AppModule {}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Step 2: Create an Application
|
|
66
|
+
|
|
67
|
+
Create and bootstrap your application.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { NexusApplicationsBrowser } from '@nexus-ioc/core/dist/server';
|
|
71
|
+
import { AppModule, AppService } from './app.module';
|
|
72
|
+
|
|
73
|
+
async function bootstrap() {
|
|
74
|
+
const app = await NexusApplicationsBrowser
|
|
75
|
+
.create(AppModule)
|
|
76
|
+
.bootstrap();
|
|
77
|
+
|
|
78
|
+
const appService = app.get<AppService>(AppService);
|
|
79
|
+
|
|
80
|
+
console.log(appService?.getHello());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
bootstrap();
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Testing
|
|
88
|
+
|
|
89
|
+
### Installation
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install @nexus-ioc/testing
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Usage
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { Injectable } from '@nexus-ioc/core';
|
|
99
|
+
import { Test } from '@nexus-ioc/testing';
|
|
100
|
+
|
|
101
|
+
describe('AppModule', () => {
|
|
102
|
+
it('should create instance', async () => {
|
|
103
|
+
@Injectable()
|
|
104
|
+
class AppService {}
|
|
105
|
+
|
|
106
|
+
const appModule = await Test.createModule({
|
|
107
|
+
providers: [AppService],
|
|
108
|
+
}).compile();
|
|
109
|
+
|
|
110
|
+
const appService = await appModule.get<AppService>(AppService);
|
|
111
|
+
expect(appService).toBeInstanceOf(AppService);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
119
|
+
|
|
120
|
+
## Author
|
|
121
|
+
|
|
122
|
+
Isqanderm (Aleksandr Melnik) - [LinkedIn](www.linkedin.com/in/isqander-melnik)
|
|
123
|
+
|
|
124
|
+
## Contributing
|
|
125
|
+
|
|
126
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
127
|
+
|
|
128
|
+
## Acknowledgements
|
|
129
|
+
|
|
130
|
+
Special thanks to the developers of Angular and NestJS for the inspiration.
|
|
131
|
+
|
|
132
|
+
## Wiki
|
|
133
|
+
|
|
134
|
+
For more detailed documentation, please visit the [Wiki](https://github.com/Isqanderm/ioc/wiki).
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from "typescript/lib/tsserverlibrary";
|
|
2
|
+
import type { NsLanguageService } from "../language-service/ns-language-service";
|
|
3
|
+
export declare const getCompletionInfoActions: (classDeclaration: ts.ClassDeclaration, tsNsLs: NsLanguageService) => ts.CompletionInfo | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCompletionInfoActions = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tsserverlibrary_1 = tslib_1.__importDefault(require("typescript/lib/tsserverlibrary"));
|
|
6
|
+
const find_type_references_helper_1 = require("../helpers/find-type-references.helper");
|
|
7
|
+
const ns_module_parser_1 = require("../parsers/ns-module.parser");
|
|
8
|
+
const ns_modules_parser_1 = require("../parsers/ns-modules.parser");
|
|
9
|
+
const getCompletionInfoActions = (classDeclaration, tsNsLs) => {
|
|
10
|
+
const typeChecker = tsNsLs.tsLS.getProgram()?.getTypeChecker();
|
|
11
|
+
if (!typeChecker) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const entries = (0, find_type_references_helper_1.findTypeReferences)(classDeclaration, tsNsLs.tsLS, tsNsLs.logger)
|
|
15
|
+
.map((item) => {
|
|
16
|
+
const sourceFile = tsNsLs.tsLS
|
|
17
|
+
.getProgram()
|
|
18
|
+
?.getSourceFile(item.fileName);
|
|
19
|
+
return ns_modules_parser_1.NsModulesParser.executeByClassDependency(sourceFile, classDeclaration, tsNsLs.logger);
|
|
20
|
+
})
|
|
21
|
+
.flatMap((items) => ns_module_parser_1.NsModuleParser.execute(items, typeChecker, tsNsLs.logger))
|
|
22
|
+
.flatMap((module) => module.providers)
|
|
23
|
+
.map((provider, index) => {
|
|
24
|
+
if (tsserverlibrary_1.default.isStringLiteral(provider.provide)) {
|
|
25
|
+
const name = provider.provide
|
|
26
|
+
.getText()
|
|
27
|
+
.replaceAll('"', "")
|
|
28
|
+
.replaceAll("'", "");
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
kind: tsserverlibrary_1.default.ScriptElementKind.string,
|
|
32
|
+
kindModifiers: "export",
|
|
33
|
+
sortText: `${index}`,
|
|
34
|
+
insertText: name,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (tsserverlibrary_1.default.isClassDeclaration(provider.provide)) {
|
|
38
|
+
return {
|
|
39
|
+
name: provider.provide.name?.text,
|
|
40
|
+
kind: tsserverlibrary_1.default.ScriptElementKind.classElement,
|
|
41
|
+
kindModifiers: "export",
|
|
42
|
+
sortText: `${index}`,
|
|
43
|
+
insertText: provider.provide.name?.text,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
})
|
|
48
|
+
.filter(Boolean);
|
|
49
|
+
return {
|
|
50
|
+
isGlobalCompletion: false,
|
|
51
|
+
isMemberCompletion: true,
|
|
52
|
+
isNewIdentifierLocation: true,
|
|
53
|
+
entries: entries,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.getCompletionInfoActions = getCompletionInfoActions;
|
|
57
|
+
//# sourceMappingURL=get-completion-info.actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-completion-info.actions.js","sourceRoot":"","sources":["../../src/actions/get-completion-info.actions.ts"],"names":[],"mappings":";;;;AACA,6FAAgD;AAChD,wFAA4E;AAE5E,kEAA6D;AAC7D,oEAA+D;AAExD,MAAM,wBAAwB,GAAG,CACvC,gBAAqC,EACrC,MAAyB,EACO,EAAE;IAClC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,CAAC;IAE/D,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO;IACR,CAAC;IAED,MAAM,OAAO,GAAG,IAAA,gDAAkB,EACjC,gBAAgB,EAChB,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,MAAM,CACb;SACC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI;aAC5B,UAAU,EAAE;YACb,EAAE,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAkB,CAAC;QACjD,OAAO,mCAAe,CAAC,wBAAwB,CAC9C,UAAU,EACV,gBAAgB,EAChB,MAAM,CAAC,MAAM,CACb,CAAC;IACH,CAAC,CAAC;SACD,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAClB,iCAAc,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CACzD;SACA,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC;SACrC,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAA0B,EAAE;QAChD,IAAI,yBAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO;iBAC3B,OAAO,EAAE;iBACT,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;iBACnB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAEtB,OAAO;gBACN,IAAI;gBACJ,IAAI,EAAE,yBAAE,CAAC,iBAAiB,CAAC,MAAM;gBACjC,aAAa,EAAE,QAAQ;gBACvB,QAAQ,EAAE,GAAG,KAAK,EAAE;gBACpB,UAAU,EAAE,IAAI;aAChB,CAAC;QACH,CAAC;QAED,IAAI,yBAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,OAAO;gBACN,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAc;gBAC3C,IAAI,EAAE,yBAAE,CAAC,iBAAiB,CAAC,YAAY;gBACvC,aAAa,EAAE,QAAQ;gBACvB,QAAQ,EAAE,GAAG,KAAK,EAAE;gBACpB,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAc;aACjD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,OAAO;QACN,kBAAkB,EAAE,KAAK;QACzB,kBAAkB,EAAE,IAAI;QACxB,uBAAuB,EAAE,IAAI;QAC7B,OAAO,EAAE,OAA4B;KACrC,CAAC;AACH,CAAC,CAAC;AAjEW,QAAA,wBAAwB,4BAiEnC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSemanticDiagnosticsActions = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = tslib_1.__importStar(require("typescript/lib/tsserverlibrary"));
|
|
6
|
+
const check_types_helper_1 = require("../helpers/check-types.helper");
|
|
7
|
+
const compare_string_types_helper_1 = require("../helpers/compare-string-types.helper");
|
|
8
|
+
const find_type_references_helper_1 = require("../helpers/find-type-references.helper");
|
|
9
|
+
const inject_parser_1 = require("../parsers/inject.parser");
|
|
10
|
+
const injectable_parser_1 = require("../parsers/injectable.parser");
|
|
11
|
+
const ns_module_parser_1 = require("../parsers/ns-module.parser");
|
|
12
|
+
const ns_modules_parser_1 = require("../parsers/ns-modules.parser");
|
|
13
|
+
const getSemanticDiagnosticsActions = (fileName, tsNsLs) => {
|
|
14
|
+
const sourceFile = tsNsLs.tsLS.getProgram()?.getSourceFile(fileName);
|
|
15
|
+
const originalDiagnostic = tsNsLs.tsLS.getSemanticDiagnostics(fileName);
|
|
16
|
+
const typeChecker = tsNsLs.tsLS.getProgram()?.getTypeChecker();
|
|
17
|
+
if (!sourceFile || !typeChecker) {
|
|
18
|
+
return originalDiagnostic;
|
|
19
|
+
}
|
|
20
|
+
const diagnostic = [];
|
|
21
|
+
const injectableClasses = injectable_parser_1.InjectableParser.execute(sourceFile);
|
|
22
|
+
if (!injectableClasses.length) {
|
|
23
|
+
return originalDiagnostic;
|
|
24
|
+
}
|
|
25
|
+
for (const injectableClass of injectableClasses) {
|
|
26
|
+
const params = inject_parser_1.InjectParser.execute(injectableClass, tsNsLs.logger);
|
|
27
|
+
if (!params.length) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
tsNsLs.logger.log(`[NsLanguageServer][getSemanticDiagnostics][params] ${params.length}`);
|
|
31
|
+
const references = (0, find_type_references_helper_1.findTypeReferences)(injectableClass, tsNsLs.tsLS, tsNsLs.logger);
|
|
32
|
+
const referenceModules = [];
|
|
33
|
+
for (const reference of references) {
|
|
34
|
+
const sourceFileReference = tsNsLs.tsLS
|
|
35
|
+
.getProgram()
|
|
36
|
+
?.getSourceFile(reference.fileName);
|
|
37
|
+
if (!sourceFileReference) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const modules = ns_modules_parser_1.NsModulesParser.executeByClassDependency(sourceFileReference, injectableClass, tsNsLs.logger);
|
|
41
|
+
const nsModule = ns_module_parser_1.NsModuleParser.execute(modules, typeChecker, tsNsLs.logger);
|
|
42
|
+
referenceModules.push(...nsModule);
|
|
43
|
+
}
|
|
44
|
+
for (const param of params) {
|
|
45
|
+
for (const referenceModule of referenceModules) {
|
|
46
|
+
let dependencyDeclare = referenceModule.providers.find((provider) => {
|
|
47
|
+
if (ts.isStringLiteral(param.name)) {
|
|
48
|
+
const name = param.name.getText();
|
|
49
|
+
if (provider.provideType !== "class") {
|
|
50
|
+
return name === provider.provide?.getText();
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (ts.isIdentifier(param.name)) {
|
|
55
|
+
return (0, check_types_helper_1.checkTypesHelper)(provider.declaration, param.name, typeChecker, tsNsLs.logger);
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
});
|
|
59
|
+
if (!dependencyDeclare) {
|
|
60
|
+
referenceModule.imports.map((module) => {
|
|
61
|
+
if (ts.isIdentifier(module.declaration)) {
|
|
62
|
+
const references = (0, find_type_references_helper_1.findTypeReferences)(module.declaration, tsNsLs.tsLS, tsNsLs.logger) || [];
|
|
63
|
+
if (!references.length) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const reference of references) {
|
|
67
|
+
const sourceFile = tsNsLs.tsLS
|
|
68
|
+
.getProgram()
|
|
69
|
+
?.getSourceFile(reference.fileName);
|
|
70
|
+
const modules = ns_modules_parser_1.NsModulesParser.executeByModuleName(sourceFile, module.declaration, typeChecker, tsNsLs.logger);
|
|
71
|
+
const nsModules = ns_module_parser_1.NsModuleParser.execute(modules, typeChecker, tsNsLs.logger);
|
|
72
|
+
for (const nsModule of nsModules) {
|
|
73
|
+
dependencyDeclare = nsModule.exports.find((provider) => {
|
|
74
|
+
if (ts.isStringLiteral(param.name)) {
|
|
75
|
+
return provider.name === param.name.getText();
|
|
76
|
+
}
|
|
77
|
+
if (ts.isIdentifier(param.name)) {
|
|
78
|
+
return (0, check_types_helper_1.checkTypesHelper)(provider.declaration, param.name, typeChecker, tsNsLs.logger);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (!dependencyDeclare) {
|
|
88
|
+
diagnostic.push({
|
|
89
|
+
file: sourceFile,
|
|
90
|
+
start: param.start,
|
|
91
|
+
length: param.length,
|
|
92
|
+
messageText: `У класса ${injectableClass.name?.text} отсутствуют зависимости: ${param.name.getText()}`,
|
|
93
|
+
category: ts.DiagnosticCategory.Error,
|
|
94
|
+
code: 9999,
|
|
95
|
+
relatedInformation: [
|
|
96
|
+
{
|
|
97
|
+
category: ts.DiagnosticCategory.Suggestion,
|
|
98
|
+
code: 9999,
|
|
99
|
+
file: referenceModule.sourceFile,
|
|
100
|
+
start: referenceModule.start,
|
|
101
|
+
length: referenceModule.length,
|
|
102
|
+
messageText: `Модуль: ${referenceModule.moduleName}`,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (dependencyDeclare?.provide && param.parameterType) {
|
|
108
|
+
let isEqual;
|
|
109
|
+
if (param.parameterType.kind === ts.SyntaxKind.StringKeyword) {
|
|
110
|
+
isEqual = (0, compare_string_types_helper_1.compareStringTypes)(param.parameterType, dependencyDeclare.declaration, typeChecker);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
isEqual = (0, check_types_helper_1.checkTypesHelper)(param.parameterType, dependencyDeclare.declaration, typeChecker, tsNsLs.logger);
|
|
114
|
+
}
|
|
115
|
+
if (!isEqual) {
|
|
116
|
+
diagnostic.push({
|
|
117
|
+
file: sourceFile,
|
|
118
|
+
start: param.start,
|
|
119
|
+
length: param.length,
|
|
120
|
+
messageText: `У зависимости ${param.name.getText()} не совпадают типы`,
|
|
121
|
+
category: ts.DiagnosticCategory.Error,
|
|
122
|
+
code: 9999,
|
|
123
|
+
relatedInformation: [
|
|
124
|
+
{
|
|
125
|
+
category: ts.DiagnosticCategory.Suggestion,
|
|
126
|
+
code: 9999,
|
|
127
|
+
file: referenceModule.sourceFile,
|
|
128
|
+
start: referenceModule.start,
|
|
129
|
+
length: referenceModule.length,
|
|
130
|
+
messageText: `Модуль: ${referenceModule.moduleName}`,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!referenceModules.length) {
|
|
138
|
+
// кейс когда мы указали зависимости в классе, но он не связан ни с одним модулем
|
|
139
|
+
diagnostic.push({
|
|
140
|
+
file: sourceFile,
|
|
141
|
+
start: param.start,
|
|
142
|
+
length: param.length,
|
|
143
|
+
messageText: `У класса ${injectableClass.name?.text} отсутствуют зависимости: ${param.name.getText()}`,
|
|
144
|
+
category: ts.DiagnosticCategory.Error,
|
|
145
|
+
code: 9999,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return [...originalDiagnostic, ...diagnostic];
|
|
151
|
+
};
|
|
152
|
+
exports.getSemanticDiagnosticsActions = getSemanticDiagnosticsActions;
|
|
153
|
+
//# sourceMappingURL=get-semantic-diagnostics.actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-semantic-diagnostics.actions.js","sourceRoot":"","sources":["../../src/actions/get-semantic-diagnostics.actions.ts"],"names":[],"mappings":";;;;AAAA,2EAAqD;AACrD,sEAAiE;AACjE,wFAA4E;AAC5E,wFAA4E;AAE5E,4DAAwD;AACxD,oEAAgE;AAChE,kEAKqC;AACrC,oEAA+D;AAExD,MAAM,6BAA6B,GAAG,CAC5C,QAAgB,EAChB,MAAyB,EACxB,EAAE;IACH,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,aAAa,CAAC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iB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB;4BACtE,QAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK;4BACrC,IAAI,EAAE,IAAI;4BACV,kBAAkB,EAAE;gCACnB;oCACC,QAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU;oCAC1C,IAAI,EAAE,IAAI;oCACV,IAAI,EAAE,eAAe,CAAC,UAAU;oCAChC,KAAK,EAAE,eAAe,CAAC,KAAK;oCAC5B,MAAM,EAAE,eAAe,CAAC,MAAM;oCAC9B,WAAW,EAAE,WAAW,eAAe,CAAC,UAAU,EAAE;iCACpD;6BACD;yBACD,CAAC,CAAC;oBACJ,CAAC;gBACF,CAAC;YACF,CAAC;YAED,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;gBAC9B,iFAAiF;gBACjF,UAAU,CAAC,IAAI,CAAC;oBACf,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,WAAW,EAAE,YAAY,eAAe,CAAC,IAAI,EAAE,IAAI,6BAA6B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE;oBACtG,QAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK;oBACrC,IAAI,EAAE,IAAI;iBACV,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,CAAC,GAAG,kBAAkB,EAAE,GAAG,UAAU,CAAC,CAAC;AAC/C,CAAC,CAAC;AAvNW,QAAA,6BAA6B,iCAuNxC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkTypesHelper = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = tslib_1.__importStar(require("typescript/lib/tsserverlibrary"));
|
|
6
|
+
const checkTypesHelper = (type1, type2, typeChecker, logger) => {
|
|
7
|
+
// Получаем символы для type1 и type2
|
|
8
|
+
const symbol1 = ts.isIdentifier(type1)
|
|
9
|
+
? typeChecker.getSymbolAtLocation(type1)
|
|
10
|
+
: typeChecker.getTypeAtLocation(type1).getSymbol();
|
|
11
|
+
const symbol2 = ts.isIdentifier(type2)
|
|
12
|
+
? typeChecker.getSymbolAtLocation(type2)
|
|
13
|
+
: typeChecker.getTypeAtLocation(type2).getSymbol();
|
|
14
|
+
if (!symbol1 || !symbol2) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (ts.isIdentifier(type1) && ts.isIdentifier(type2)) {
|
|
18
|
+
return (symbol1.escapedName === symbol2.escapedName &&
|
|
19
|
+
symbol1.declarations?.[-1]?.getSourceFile().fileName ===
|
|
20
|
+
symbol2.declarations?.[-1]?.getSourceFile().fileName);
|
|
21
|
+
}
|
|
22
|
+
// Получаем типы по символам
|
|
23
|
+
const typeLocation1 = typeChecker.getTypeOfSymbolAtLocation(symbol1, type1);
|
|
24
|
+
const typeLocation2 = typeChecker.getTypeOfSymbolAtLocation(symbol2, type2);
|
|
25
|
+
// Проверяем, что типы взаимно совместимы
|
|
26
|
+
return (typeChecker.isTypeAssignableTo(typeLocation1, typeLocation2) &&
|
|
27
|
+
typeChecker.isTypeAssignableTo(typeLocation2, typeLocation1));
|
|
28
|
+
};
|
|
29
|
+
exports.checkTypesHelper = checkTypesHelper;
|
|
30
|
+
//# sourceMappingURL=check-types.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-types.helper.js","sourceRoot":"","sources":["../../src/helpers/check-types.helper.ts"],"names":[],"mappings":";;;;AAAA,2EAAqD;AAG9C,MAAM,gBAAgB,GAAG,CAC/B,KAAc,EACd,KAAc,EACd,WAA2B,EAC3B,MAAc,EACJ,EAAE;IACZ,qCAAqC;IACrC,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC;QAC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, "__esModule", { value: true });
|
|
3
|
+
exports.compareStringTypes = compareStringTypes;
|
|
4
|
+
const get_type_of_node_helper_1 = require("./get-type-of-node.helper");
|
|
5
|
+
function compareStringTypes(keywordNode, // Узел с типом string (StringKeyword)
|
|
6
|
+
literalNode, // Узел со строковым литералом (StringLiteral)
|
|
7
|
+
typeChecker) {
|
|
8
|
+
const keywordType = (0, get_type_of_node_helper_1.getTypeOfNode)(keywordNode, typeChecker);
|
|
9
|
+
const literalType = (0, get_type_of_node_helper_1.getTypeOfNode)(literalNode, typeChecker);
|
|
10
|
+
if (!keywordType || !literalType) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
// Проверяем, можно ли строковый литерал привести к string
|
|
14
|
+
return typeChecker.isTypeAssignableTo(literalType, keywordType);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=compare-string-types.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare-string-types.helper.js","sourceRoot":"","sources":["../../src/helpers/compare-string-types.helper.ts"],"names":[],"mappings":";;AAIA,gDAcC;AAhBD,uEAA0D;AAE1D,SAAgB,kBAAkB,CACjC,WAAoB,EAAE,sCAAsC;AAC5D,WAAoB,EAAE,8CAA8C;AACpE,WAA2B;IAE3B,MAAM,WAAW,GAAG,IAAA,uCAAa,EAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC5D,MAAM,WAAW,GAAG,IAAA,uCAAa,EAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAE5D,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,0DAA0D;IAC1D,OAAO,WAAW,CAAC,kBAAkB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findNodeAtPosition = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tsserverlibrary_1 = tslib_1.__importDefault(require("typescript/lib/tsserverlibrary"));
|
|
6
|
+
const findNodeAtPosition = (sourceFile, position) => {
|
|
7
|
+
function find(node) {
|
|
8
|
+
if (position >= node.getStart() && position <= node.getEnd()) {
|
|
9
|
+
return tsserverlibrary_1.default.forEachChild(node, find) || node;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return find(sourceFile);
|
|
14
|
+
};
|
|
15
|
+
exports.findNodeAtPosition = findNodeAtPosition;
|
|
16
|
+
//# sourceMappingURL=find-node-at-position.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-node-at-position.helper.js","sourceRoot":"","sources":["../../src/helpers/find-node-at-position.helper.ts"],"names":[],"mappings":";;;;AAAA,6FAAgD;AAEzC,MAAM,kBAAkB,GAAG,CACjC,UAAyB,EACzB,QAAgB,EACM,EAAE;IACxB,SAAS,IAAI,CAAC,IAAa;QAC1B,IAAI,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,IAAI,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YAC9D,OAAO,yBAAE,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;QAC5C,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;AACzB,CAAC,CAAC;AAZW,QAAA,kBAAkB,sBAY7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as ts from "typescript/lib/tsserverlibrary";
|
|
2
|
+
import type { Logger } from "../logger";
|
|
3
|
+
export type TypeReference = {
|
|
4
|
+
fileName: string;
|
|
5
|
+
textSpan: ts.TextSpan[];
|
|
6
|
+
isDefinition: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const findTypeReferences: (typeNode: ts.ClassDeclaration | ts.TypeReferenceNode | ts.Identifier, languageService: ts.LanguageService, logger: Logger) => TypeReference[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findTypeReferences = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = tslib_1.__importStar(require("typescript/lib/tsserverlibrary"));
|
|
6
|
+
const findTypeReferences = (typeNode, languageService, logger) => {
|
|
7
|
+
const typeChecker = languageService.getProgram()?.getTypeChecker();
|
|
8
|
+
let identifier;
|
|
9
|
+
let sourceFile = null;
|
|
10
|
+
if (!typeChecker) {
|
|
11
|
+
logger.log("[findTypeReferences] typeChecker is not define");
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
if (ts.isClassDeclaration(typeNode) && typeNode.name) {
|
|
15
|
+
identifier = typeNode.name;
|
|
16
|
+
sourceFile = typeNode.getSourceFile();
|
|
17
|
+
}
|
|
18
|
+
else if (ts.isTypeReferenceNode(typeNode) &&
|
|
19
|
+
ts.isIdentifier(typeNode.typeName)) {
|
|
20
|
+
identifier = typeNode.typeName;
|
|
21
|
+
sourceFile = typeNode.getSourceFile();
|
|
22
|
+
}
|
|
23
|
+
else if (ts.isIdentifier(typeNode)) {
|
|
24
|
+
identifier = typeNode;
|
|
25
|
+
sourceFile = identifier.getSourceFile();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error("Unsupported node type. Only ClassDeclaration, TypeReferenceNode, and Identifier are supported.");
|
|
29
|
+
}
|
|
30
|
+
if (!sourceFile) {
|
|
31
|
+
throw new Error("sourceFile not define");
|
|
32
|
+
}
|
|
33
|
+
const identifierPosition = identifier.getStart();
|
|
34
|
+
const references = languageService.findReferences(sourceFile.fileName, identifierPosition) ||
|
|
35
|
+
[];
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const ref of references) {
|
|
38
|
+
for (const refDetail of ref.references) {
|
|
39
|
+
const typeReference = result[refDetail.fileName] || {
|
|
40
|
+
fileName: refDetail.fileName,
|
|
41
|
+
textSpan: [],
|
|
42
|
+
isDefinition: refDetail.isDefinition || false,
|
|
43
|
+
};
|
|
44
|
+
typeReference.textSpan.push(refDetail.textSpan);
|
|
45
|
+
result[refDetail.fileName] = typeReference;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return Object.values(result);
|
|
49
|
+
};
|
|
50
|
+
exports.findTypeReferences = findTypeReferences;
|
|
51
|
+
//# sourceMappingURL=find-type-references.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-type-references.helper.js","sourceRoot":"","sources":["../../src/helpers/find-type-references.helper.ts"],"names":[],"mappings":";;;;AAAA,2EAAqD;AAS9C,MAAM,kBAAkB,GAAG,CACjC,QAAoE,EACpE,eAAmC,EACnC,MAAc,EACI,EAAE;IACpB,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,CAAC;IACnE,IAAI,UAAqC,CAAC;IAC1C,IAAI,UAAU,GAAyB,IAAI,CAAC;IAE5C,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,MAAM,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAC7D,OAAO,EAAE,CAAC;IACX,CAAC;IAED,IAAI,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtD,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC3B,UAAU,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;IACvC,CAAC;SAAM,IACN,EAAE,CAAC,mBAAmB,CAAC,QAAQ,CAAC;QAChC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACjC,CAAC;QACF,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAC/B,UAAU,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC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
4
|
+
const getTypeOfNode = (node, typeChecker) => {
|
|
5
|
+
try {
|
|
6
|
+
return typeChecker.getTypeAtLocation(node);
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
console.error("Failed to get type:", error);
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.getTypeOfNode = getTypeOfNode;
|
|
14
|
+
//# sourceMappingURL=get-type-of-node.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-type-of-node.helper.js","sourceRoot":"","sources":["../../src/helpers/get-type-of-node.helper.ts"],"names":[],"mappings":";;;AAEO,MAAM,aAAa,GAAG,CAC5B,IAAa,EACb,WAA2B,EACL,EAAE;IACxB,IAAI,CAAC;QACJ,OAAO,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC5C,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC,CAAC;AAVW,QAAA,aAAa,iBAUxB"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tslib_1 = require("tslib");
|
|
3
|
+
const ts = tslib_1.__importStar(require("typescript/lib/tsserverlibrary"));
|
|
4
|
+
const get_completion_info_actions_1 = require("./actions/get-completion-info.actions");
|
|
5
|
+
const get_semantic_diagnostics_actions_1 = require("./actions/get-semantic-diagnostics.actions");
|
|
6
|
+
const find_node_at_position_helper_1 = require("./helpers/find-node-at-position.helper");
|
|
7
|
+
const ns_language_service_1 = require("./language-service/ns-language-service");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
const plugin = () => {
|
|
10
|
+
return {
|
|
11
|
+
create: (pluginCreateInfo) => {
|
|
12
|
+
const config = pluginCreateInfo.config;
|
|
13
|
+
const tsConfigDirectory = pluginCreateInfo.languageServiceHost.getCurrentDirectory();
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
15
|
+
const logger = new logger_1.Logger(config);
|
|
16
|
+
const tsNsLs = new ns_language_service_1.NsLanguageService(pluginCreateInfo.project, pluginCreateInfo.serverHost, pluginCreateInfo.languageService, config, logger);
|
|
17
|
+
return new Proxy(pluginCreateInfo.languageService, {
|
|
18
|
+
get: (target, property) => {
|
|
19
|
+
if (property === "getSemanticDiagnostics") {
|
|
20
|
+
return (fileName) => {
|
|
21
|
+
const program = pluginCreateInfo.languageService.getProgram();
|
|
22
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
23
|
+
if (!sourceFile || !program) {
|
|
24
|
+
return target.getSemanticDiagnostics(fileName);
|
|
25
|
+
}
|
|
26
|
+
const originalDiagnostic = target.getSemanticDiagnostics(fileName);
|
|
27
|
+
// CODE
|
|
28
|
+
const diagnostic = (0, get_semantic_diagnostics_actions_1.getSemanticDiagnosticsActions)(fileName, tsNsLs);
|
|
29
|
+
return [...originalDiagnostic, ...diagnostic];
|
|
30
|
+
// CODE
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (property === "getCompletionsAtPosition") {
|
|
34
|
+
return (fileName, position, options) => {
|
|
35
|
+
const program = pluginCreateInfo.languageService.getProgram();
|
|
36
|
+
const defaultCompletionsAtPosition = target.getCompletionsAtPosition(fileName, position, options);
|
|
37
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
38
|
+
if (!program || !sourceFile) {
|
|
39
|
+
return defaultCompletionsAtPosition;
|
|
40
|
+
}
|
|
41
|
+
const node = (0, find_node_at_position_helper_1.findNodeAtPosition)(sourceFile, position);
|
|
42
|
+
if (!node || !ts.isCallExpression(node.parent)) {
|
|
43
|
+
return defaultCompletionsAtPosition;
|
|
44
|
+
}
|
|
45
|
+
const injectExpressionNode = node.parent;
|
|
46
|
+
if (ts.isIdentifier(injectExpressionNode.expression) &&
|
|
47
|
+
injectExpressionNode.expression.text === "Inject") {
|
|
48
|
+
const injectDecoratorNode = injectExpressionNode.parent;
|
|
49
|
+
const classDeclarationNode = injectDecoratorNode.parent.parent.parent;
|
|
50
|
+
return (0, get_completion_info_actions_1.getCompletionInfoActions)(classDeclarationNode, tsNsLs);
|
|
51
|
+
}
|
|
52
|
+
return defaultCompletionsAtPosition;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return target[property];
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
module.exports = plugin;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|