ctx/internal/plugins/csharp/outline.go
Ricardo Carneiro 22f6e8fde9 chore: add golangci-lint, GitHub Actions CI, and pre-commit hooks
Adds .golangci.yml (errcheck, govet, staticcheck, revive, gocyclo,
gocritic, nilerr, errorlint, etc.). Fixes all lint issues found:
- RpcError/wrapRpc renamed to RPCError/wrapRPC (revive var-naming)
- Shadow vars resolved in process.go, outline.go, project.go
- nilerr suppressed with justifying comments in git/collect.go and
  auto/detector.go (WalkDir / intentional empty-returns)
- if-else chain rewritten as switch in format.go (gocritic)
- gofmt applied to detector.go and client.go

Adds .github/workflows/ci.yml: lint (ubuntu), build+vet+test matrix
(ubuntu/windows/macos), and Roslyn helper build (windows). Validated
with actionlint (0 issues).

Adds .githooks/pre-commit + pre-commit.ps1 for local pre-commit checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 00:30:54 -03:00

69 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package csharp
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/ricarneiro/ctx/internal/core"
"github.com/ricarneiro/ctx/internal/plugins/csharp/helper"
"github.com/spf13/cobra"
)
func outlineCmd(ctx *core.Context) *cobra.Command {
return &cobra.Command{
Use: "outline <file.cs>",
Short: "Show structural outline of a C# file (no method bodies)",
Long: `Parse a C# source file and emit its structural skeleton:
namespaces, types, method signatures, properties, fields, events.
Method bodies are omitted — reduces large files by 8090%.
Does not require a loaded solution. Works on a single file.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runOutline(ctx, args[0])
},
}
}
func runOutline(ctx *core.Context, file string) error {
abs, err := resolveFilePath(ctx.WorkDir, file)
if err != nil {
fmt.Fprintln(ctx.Stderr, err.Error())
return errExit
}
if !strings.HasSuffix(strings.ToLower(abs), ".cs") {
fmt.Fprintf(ctx.Stderr, "not a C# file: %s\n", abs)
return errExit
}
if _, statErr := os.Stat(abs); statErr != nil {
fmt.Fprintf(ctx.Stderr, "file not found: %s\n", abs)
return errExit
}
client, err := helper.NewClient()
if err != nil {
fmt.Fprintln(ctx.Stderr, err.Error())
return errExit
}
defer client.Close()
outline, err := client.Outline(abs)
if err != nil {
fmt.Fprintln(ctx.Stderr, err.Error())
return errExit
}
return WriteOutline(ctx.Stdout, outline)
}
func resolveFilePath(workDir, file string) (string, error) {
if filepath.IsAbs(file) {
return filepath.Clean(file), nil
}
return filepath.Clean(filepath.Join(workDir, file)), nil
}