captbaritone / grats

Implementation-First GraphQL for TypeScript

Home Page:https://grats.capt.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TS Plugin Feature Ideas

captbaritone opened this issue · comments

  • Show SDL in hover tip
  • Use semantic highlighting to color docblock tags
  • Refactor/quickfix suggestions
  • Show SDL in inlay text

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];
    };

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