Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS Plugin Feature Ideas #115

Open
4 tasks
captbaritone opened this issue Jan 25, 2024 · 2 comments
Open
4 tasks

TS Plugin Feature Ideas #115

captbaritone opened this issue Jan 25, 2024 · 2 comments

Comments

@captbaritone
Copy link
Owner

  • Show SDL in hover tip
  • Use semantic highlighting to color docblock tags
  • Refactor/quickfix suggestions
  • Show SDL in inlay text
@captbaritone
Copy link
Owner Author

Sketch of inlay hints

    proxy.provideInlayHints = (fileName, range, context) => {
      const prior = info.languageService.provideInlayHints(
        fileName,
        range,
        context,
      );

      const doc = info.languageService.getProgram()?.getSourceFile(fileName);

      if (doc == null) return prior;
      const result = extract(doc);

      if (result.kind === "ERROR") return prior;

      const hints = result.value.definitions
        .map((def) => {
          if (
            def.kind === Kind.OBJECT_TYPE_DEFINITION &&
            def.name.loc != null
          ) {
            return {
              text: `${def.name.value}`,
              position: def.name.loc.end,
              kind: ts.InlayHintKind.Type,
            };
          }
        })
        .filter((hint): hint is TS.InlayHint => hint != null);

      return [...prior, ...hints];
    };

@captbaritone
Copy link
Owner Author

captbaritone commented Mar 26, 2024

Sketch of code actions

   proxy.getCodeFixesAtPosition = (
      fileName: string,
      start: number,
      end: number,
      errorCodes: readonly number[],
      formatOptions: TS.FormatCodeSettings,
      preferences: TS.UserPreferences,
    ): readonly TS.CodeFixAction[] => {
      const prior = info.languageService.getCodeFixesAtPosition(
        fileName,
        start,
        end,
        errorCodes,
        formatOptions,
        preferences,
      );
      const doc = info.languageService.getProgram()?.getSourceFile(fileName);

      if (doc == null) return prior;
      const result = extract(doc);

      if (result.kind === "OK") return prior;

      const relatedDiagnostics = result.err.filter((err) => {
        return (
          err.fix != null &&
          err.start === start &&
          err.length === end - start &&
          err.file.fileName === doc.fileName &&
          errorCodes.includes(err.code)
        );
      });

      const fixes = relatedDiagnostics.map((err) => {
        return err.fix!;
      });

      return [...prior, ...fixes];
    };

Note: Need to define getSupportedCodeFixes

https://www.threads.net/@captbaritone/post/C49lzTfOkEt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant