@nexus-ioc/language-service 0.1.0 → 0.2.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.
Files changed (48) hide show
  1. package/README.md +46 -71
  2. package/dist/actions/get-completion-info.actions.js +4 -6
  3. package/dist/actions/get-completion-info.actions.js.map +1 -1
  4. package/dist/actions/get-semantic-diagnostics.actions.d.ts +13 -0
  5. package/dist/actions/get-semantic-diagnostics.actions.js +467 -48
  6. package/dist/actions/get-semantic-diagnostics.actions.js.map +1 -1
  7. package/dist/actions/go-to-dependency-definition.actions.d.ts +18 -0
  8. package/dist/actions/go-to-dependency-definition.actions.js +73 -0
  9. package/dist/actions/go-to-dependency-definition.actions.js.map +1 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +37 -4
  12. package/dist/index.js.map +1 -1
  13. package/dist/language-service/ns-language-service.d.ts +6 -5
  14. package/dist/language-service/ns-language-service.js +8 -2
  15. package/dist/language-service/ns-language-service.js.map +1 -1
  16. package/dist/language-service/parse-config-service.js +1 -0
  17. package/dist/language-service/parse-config-service.js.map +1 -1
  18. package/dist/language-service/types.d.ts +0 -1
  19. package/dist/logger.js +1 -0
  20. package/dist/logger.js.map +1 -1
  21. package/package.json +19 -11
  22. package/dist/helpers/check-types.helper.d.ts +0 -3
  23. package/dist/helpers/check-types.helper.js +0 -30
  24. package/dist/helpers/check-types.helper.js.map +0 -1
  25. package/dist/helpers/compare-string-types.helper.d.ts +0 -4
  26. package/dist/helpers/compare-string-types.helper.js +0 -16
  27. package/dist/helpers/compare-string-types.helper.js.map +0 -1
  28. package/dist/helpers/find-node-at-position.helper.d.ts +0 -2
  29. package/dist/helpers/find-node-at-position.helper.js +0 -16
  30. package/dist/helpers/find-node-at-position.helper.js.map +0 -1
  31. package/dist/helpers/find-type-references.helper.d.ts +0 -8
  32. package/dist/helpers/find-type-references.helper.js +0 -51
  33. package/dist/helpers/find-type-references.helper.js.map +0 -1
  34. package/dist/helpers/get-type-of-node.helper.d.ts +0 -2
  35. package/dist/helpers/get-type-of-node.helper.js +0 -14
  36. package/dist/helpers/get-type-of-node.helper.js.map +0 -1
  37. package/dist/parsers/inject.parser.d.ts +0 -16
  38. package/dist/parsers/inject.parser.js +0 -44
  39. package/dist/parsers/inject.parser.js.map +0 -1
  40. package/dist/parsers/injectable.parser.d.ts +0 -5
  41. package/dist/parsers/injectable.parser.js +0 -13
  42. package/dist/parsers/injectable.parser.js.map +0 -1
  43. package/dist/parsers/ns-module.parser.d.ts +0 -45
  44. package/dist/parsers/ns-module.parser.js +0 -237
  45. package/dist/parsers/ns-module.parser.js.map +0 -1
  46. package/dist/parsers/ns-modules.parser.d.ts +0 -7
  47. package/dist/parsers/ns-modules.parser.js +0 -35
  48. package/dist/parsers/ns-modules.parser.js.map +0 -1
package/README.md CHANGED
@@ -2,14 +2,17 @@
2
2
  ![license](https://img.shields.io/npm/l/@nexus-ioc/cpre)
3
3
  ![build](https://img.shields.io/github/actions/workflow/status/Isqanderm/ioc/build.yml)
4
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.
5
+ [Nexus IoC](https://www.npmjs.com/package/@nexus-ioc/core) 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
+
6
8
 
7
9
  ## Table of Contents
8
10
 
9
11
  - [Features](#features)
10
12
  - [Installation](#installation)
11
13
  - [Quick Start](#quick-start)
12
- - [Testing](#testing)
14
+ - [Example Project](#example-project)
15
+ - [Roadmap](#roadmap)
13
16
  - [License](#license)
14
17
  - [Author](#author)
15
18
  - [Contributing](#contributing)
@@ -18,100 +21,72 @@ Nexus IoC is a powerful and flexible Inversion of Control (IoC) container for Ty
18
21
 
19
22
  ## Features
20
23
 
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.
24
+ This plugin adds the ability to autocomplete for dependencies and highlight type errors.
25
25
 
26
26
  ## Installation
27
27
 
28
28
  ```bash
29
- npm install @nexus-ioc/core reflect-metadata
29
+ npm install @nexus-ioc/language-service
30
30
  ```
31
31
 
32
32
  ## Quick Start
33
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
- }
34
+ ### Step 1: Define plugin in tsconfig.json
53
35
 
54
- getHello(): string {
55
- return `Hello ${this.dependencyService.name}!`;
36
+ ```json
37
+ {
38
+ "compilerOptions": {
39
+ "plugins": [
40
+ {
41
+ "name": "@nexus-ioc/language-service"
42
+ }
43
+ ]
56
44
  }
57
45
  }
58
46
 
59
- @NsModule({
60
- providers: [AppService, DependencyService],
61
- })
62
- export class AppModule {}
63
47
  ```
64
48
 
65
- ### Step 2: Create an Application
49
+ ### Child containers
66
50
 
67
- Create and bootstrap your application.
51
+ Modules declared in `@Module({ children })` are analysed as child scopes. A missing-dependency error in a child scope is suppressed when the declaring module can see the token in the parent graph. A module that is also imported outside a child scope keeps the diagnostic. Tokens the declaring module sees only through a re-export are not recognised yet. Tokens supplied per child instance (the `providers` of `forProfile()` or another dynamic module, or `createChild(..., { providers })`) are not visible to static analysis, so they may be reported as missing. See [Child containers](../ioc/README.md#child-containers).
68
52
 
69
- ```typescript
70
- import { NexusApplicationsBrowser } from '@nexus-ioc/core/dist/server';
71
- import { AppModule, AppService } from './app.module';
53
+ ## Example Project
72
54
 
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
- ```
55
+ A comprehensive example project is available in the `example/` directory that demonstrates all plugin features:
86
56
 
87
- ## Testing
88
-
89
- ### Installation
57
+ - ✅ Auto-completion for `@Inject()` decorators
58
+ - ✅ Go-to-definition for dependency tokens
59
+ - ✅ Semantic diagnostics for DI errors
60
+ - ✅ Working examples with proper module configuration
61
+ - ✅ Error examples showing common mistakes
90
62
 
63
+ **Quick Start**:
91
64
  ```bash
92
- npm install @nexus-ioc/testing
93
- ```
65
+ # From monorepo root
66
+ cd packages/language-service/example
67
+ npm install
68
+ npm run build
94
69
 
95
- ### Usage
70
+ # Open in your IDE
71
+ code .
72
+ ```
96
73
 
97
- ```typescript
98
- import { Injectable } from '@nexus-ioc/core';
99
- import { Test } from '@nexus-ioc/testing';
74
+ See [`example/README.md`](./example/README.md) for detailed setup instructions and [`example/TESTING_GUIDE.md`](./example/TESTING_GUIDE.md) for comprehensive testing procedures.
100
75
 
101
- describe('AppModule', () => {
102
- it('should create instance', async () => {
103
- @Injectable()
104
- class AppService {}
76
+ ## Roadmap
105
77
 
106
- const appModule = await Test.createModule({
107
- providers: [AppService],
108
- }).compile();
78
+ See [`ROADMAP.md`](./ROADMAP.md) for the complete feature roadmap including:
79
+ - Current capabilities and limitations
80
+ - Planned enhancements (Phases 2-6)
81
+ - Effort estimates and prioritization
82
+ - Success metrics
109
83
 
110
- const appService = await appModule.get<AppService>(AppService);
111
- expect(appService).toBeInstanceOf(AppService);
112
- });
113
- });
114
- ```
84
+ **Highlights**:
85
+ - **Phase 2**: Support for `@Optional()`, `@Global()`, property injection, circular dependency detection
86
+ - **Phase 3**: Quick fixes (auto-add providers, import modules, fix type mismatches)
87
+ - **Phase 4**: Refactoring support (rename tokens, extract to module)
88
+ - **Phase 5**: Performance optimizations, hover info, inlay hints
89
+ - **Phase 6**: Dependency graph visualization, testing support
115
90
 
116
91
  ## License
117
92
 
@@ -2,23 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCompletionInfoActions = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const type_checker_1 = require("@nexus-ioc/type-checker");
5
6
  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
7
  const getCompletionInfoActions = (classDeclaration, tsNsLs) => {
10
8
  const typeChecker = tsNsLs.tsLS.getProgram()?.getTypeChecker();
11
9
  if (!typeChecker) {
12
10
  return;
13
11
  }
14
- const entries = (0, find_type_references_helper_1.findTypeReferences)(classDeclaration, tsNsLs.tsLS, tsNsLs.logger)
12
+ const entries = (0, type_checker_1.findTypeReferences)(classDeclaration, tsNsLs)
15
13
  .map((item) => {
16
14
  const sourceFile = tsNsLs.tsLS
17
15
  .getProgram()
18
16
  ?.getSourceFile(item.fileName);
19
- return ns_modules_parser_1.NsModulesParser.executeByClassDependency(sourceFile, classDeclaration, tsNsLs.logger);
17
+ return type_checker_1.ModulesParser.executeByClassDependency(sourceFile, classDeclaration, tsNsLs);
20
18
  })
21
- .flatMap((items) => ns_module_parser_1.NsModuleParser.execute(items, typeChecker, tsNsLs.logger))
19
+ .flatMap((items) => type_checker_1.ModuleParser.execute(items, typeChecker, tsNsLs))
22
20
  .flatMap((module) => module.providers)
23
21
  .map((provider, index) => {
24
22
  if (tsserverlibrary_1.default.isStringLiteral(provider.provide)) {
@@ -1 +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,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AED,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"}
1
+ {"version":3,"file":"get-completion-info.actions.js","sourceRoot":"","sources":["../../src/actions/get-completion-info.actions.ts"],"names":[],"mappings":";;;;AAAA,0DAIiC;AAEjC,6FAAgD;AAGzC,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,iCAAkB,EAAC,gBAAgB,EAAE,MAAM,CAAC;SAC1D,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,4BAAa,CAAC,wBAAwB,CAC5C,UAAU,EACV,gBAAgB,EAChB,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EAAE,OAA4B;KACrC,CAAC;AACH,CAAC,CAAC;AA3DW,QAAA,wBAAwB,4BA2DnC"}
@@ -1,3 +1,16 @@
1
1
  import * as ts from "typescript/lib/tsserverlibrary";
2
2
  import type { NsLanguageService } from "../language-service/ns-language-service";
3
+ /**
4
+ * Generates semantic diagnostics for Nexus IoC dependency injection
5
+ *
6
+ * Analyzes @Injectable classes and their @Inject decorators to detect:
7
+ * - Missing dependencies (not provided in any module)
8
+ * - Type mismatches between injected and provided types
9
+ * - Services not connected to any module
10
+ * - Circular dependencies
11
+ *
12
+ * @param fileName - The source file to analyze
13
+ * @param tsNsLs - The Nexus IoC Language Service instance
14
+ * @returns Array of TypeScript diagnostics including original diagnostics and DI-specific errors
15
+ */
3
16
  export declare const getSemanticDiagnosticsActions: (fileName: string, tsNsLs: NsLanguageService) => ts.Diagnostic[];