Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

```bash
npm run compile # TypeScript compile
npm run watch # compile in watch mode
npm run lint # ESLint on src/
npm run lint-fix # ESLint with auto-fix
npm run test-jest # run unit tests (no VS Code host needed)
npm run test-jest-coverage
npm test # integration tests (requires real VS Code)
npm run vscode:package # build .vsix
```

Run a single test file:
```bash
npx jest src/utils/csharp-util.test.ts --verbose
```

Run a single test by name:
```bash
npx jest --testNamePattern="should return the namespace" --verbose
```

CI runs `npm run pretest` (compile + lint) then `npm run test-jest-coverage`.

## Architecture

VS Code extension (TypeScript) that pulls C# class members up to an interface or base class. Activates only on `onLanguage:csharp`.

### Entry point

`src/extension.ts` registers one command: `pulltointerfacor.pullto`. On invoke it calls `csharp.getSubCommandsAsync()` to discover all inherited types, shows a `showQuickPick` dropdown, then dynamically registers per-target sub-commands (`pulltointerfacor.pullto.<TargetName>`).

### Core modules

`src/pull-to-interface-csharp.ts` -- all high-level orchestration:
- `getSubCommandsAsync`: parses the active file, extracts inherited type names, recursively opens each `.cs` file to walk the full inheritance chain
- `getSignatureToPull`: walks up from cursor to find the member declaration, formats it for interface/base-class insertion
- `addMemberToDocument`: finds the target type declaration via regex, inserts the member inside its opening brace
- `addUsingsToDocument`: merges `using` statements from source into target, deduplicating
- `applyEditsAsync`: applies transformed file content via `WorkspaceEdit.replace()` over the full file range

Behavior differs by target type:
- **Interface** (name starts with `I`): inserts signature only, nothing removed from source
- **Base class**: copies full member body to base, removes member from source file
- **Protected members**: interfaces are filtered from the target list (interfaces cannot have protected members)

`src/utils/csharp-util.ts` -- all C# text parsing:
- `SignatureLineResult` -- central DTO carrying `signature`, `signatureType` (enum: `FullProperty | LambaProperty | Method | Unknown`), `lineMatchStartsOn`, `accessor`, and `preSignatureContent` (attributes/XML doc lines above the member)
- `getMemberBodyByBrackets` / `getMemberBodyBySemiColon` -- extract full member bodies for base-class pulls

`src/interfaces/window.interface.ts` -- `IWindow` abstraction over `vscode.window` (`activeTextEditor`, `showErrorMessage`, `showInformationMessage`). Passed into all functions so unit tests work without a real VS Code host.

### Testing

Jest with `ts-jest`. VS Code API mocked globally via `__mocks__/vscode.js` (delegates to `jest-mock-vscode`). Tests use `MockTextEditor` and `createTextDocument` to simulate editor state with cursor positions. Test files live alongside source (`*.test.ts`) except integration tests in `src/test/`.

`Sample/SampleProject/` is a .NET 8 C# console project used only for manual extension testing -- ignore it in code changes.

`src/pull-to-interface-typescript.ts` is an unused stub -- not wired into the extension command.
7 changes: 7 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"Bash(npx jest *)"
]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v4.1.1
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release to Marketplace

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.1

- name: Use Node.js 20.x
uses: actions/setup-node@v4.0.2
with:
node-version: '20.x'
cache: 'npm'

- run: npm ci

- name: Lint and compile
run: npm run pretest

- name: Run tests
run: npm run test-jest

- name: Stamp version with run number
run: |
MAJOR_MINOR=$(node -p "require('./package.json').version" | cut -d. -f1-2)
npm version "${MAJOR_MINOR}.${{ github.run_number }}" --no-git-tag-version

- name: Publish to VS Code Marketplace
run: npx vsce publish --pat ${{ secrets.VSCE_PAT }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ dist
**/bin
**/obj
*.vsix
bash.exe.stackdump
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
]
}
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "openOnFirstSessionStart"
}
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"cSpell.words": [
"Lamba",
"Lamda",
"Linq"
]
}
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Loading
Loading