Skip to content

cutalion/vscode-projectionist

Repository files navigation

VSCode Projectionist

A VSCode extension that provides project-aware file navigation and creation, inspired by vim-projectionist by Tim Pope.

Attribution

This extension is inspired by and based on concepts from Tim Pope's excellent vim-projectionist plugin. We're grateful for his innovative work in creating the original projectionist system that enables efficient project navigation.

Features

  • Alternate File Navigation: Quickly switch between related files (e.g., source ↔ test)
  • Related File Discovery: Find all files related to the current file
  • Template-based File Creation: Create new files with predefined templates
  • Project Configuration: Configure file relationships via .projections.json

Commands

  • Switch to Alternate File (Ctrl+A): Navigate to the alternate file
  • Switch to Related File: Show quick pick of all related files
  • Create File from Template: Create a new file with template content
  • Reload Projections: Reload the .projections.json configuration

Configuration

Create a .projections.json file in your project root to define file relationships:

{
  "src/*.ts": {
    "alternate": "test/{}.test.ts",
    "type": "source",
    "template": [
      "export class {} {",
      "    // Implementation here",
      "}"
    ]
  },
  "test/*.test.ts": {
    "alternate": "src/{}.ts",
    "type": "test"
  }
}

Configuration Options

  • alternate: Primary alternate file pattern
  • related: Array of related file patterns
  • type: File type identifier
  • template: Array of template lines for new files

Development

Testing

This project includes comprehensive tests covering all core functionality:

npm install          # Install dependencies
npm run compile      # Compile TypeScript
npm run lint         # Run ESLint
npm test             # Run all tests

Test Structure

  • test/suite/transformations.test.ts - Tests for placeholder transformations
  • test/suite/projections.test.ts - Tests for projection management and file matching
  • test/suite/extension.test.ts - Integration tests for VSCode extension

Running Individual Tests

Use VSCode's built-in test runner or:

npm run compile && npm test

Placeholders and Transformations

Use {} as a placeholder for the matched portion of the file path. You can apply transformations:

  • {|dot}: Replace / with .
  • {|underscore}: Replace / with _
  • {|camelcase}: Convert to camelCase
  • {|snakecase}: Convert to snake_case
  • {|uppercase}: Convert to UPPERCASE
  • {|lowercase}: Convert to lowercase
  • {|dirname}: Get directory name
  • {|basename}: Get file name
  • {|file}: Get file name without extension
  • {|ext}: Get file extension

Example Configurations

React Project

{
  "src/components/*.tsx": {
    "alternate": "src/components/{}.test.tsx",
    "related": ["src/components/{}.module.css", "src/components/{}.stories.tsx"],
    "template": [
      "import React from 'react';",
      "",
      "export const {}: React.FC = () => {",
      "    return <div>{}</div>;",
      "};"
    ]
  }
}

Java Project

{
  "src/main/java/**/*.java": {
    "alternate": "src/test/java/{}.java",
    "template": [
      "package {|dirname|dot};",
      "",
      "public class {} {",
      "",
      "}"
    ]
  }
}

Installation

  1. Package the extension: vsce package
  2. Install the .vsix file in VSCode

Development

  1. Clone this repository
  2. Run npm install
  3. Run npm run compile
  4. Press F5 to launch a new Extension Development Host

Differences from vim-projectionist

While this extension is inspired by vim-projectionist, there are some differences due to the VSCode environment:

  • UI Integration: Uses VSCode's quick pick interface instead of Vim's command line
  • File System: Uses VSCode's file system APIs for better integration
  • Configuration: Same .projections.json format for compatibility
  • Commands: Adapted to VSCode's command palette system

Contributing Back

If you find this extension useful, please consider:

License

MIT - See LICENSE file for details.

This project includes attribution to Tim Pope's original vim-projectionist work.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published