Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Track Current FileNew to Visual Studio Code? Get it now.
Track Current File

Track Current File

MustafaLo

|
33 installs
| (0) | Free
Tracks the currently active file in VSCode and updates a json file with metadata
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Track Current File

Version: 0.0.2
Repository: GitHub: File-Tracker-Extension


Overview

The Track Current File extension for VSCode tracks the currently active file in your editor and automatically updates a fileMetadata.json file in your workspace directory. This is particularly useful for tools like CLI applications that need context about the active file (e.g., file name, path, or selected lines).

The fileMetadata.json file is updated dynamically when:

  1. You switch between files.
  2. You select or highlight lines in a file.
  3. You run the Current File Tracker command from the Command Palette.

Fields Tracked

The metadata written to fileMetadata.json includes the following fields:

Field Description
fileName The name of the currently active file (e.g., main.go).
filePath The full path to the currently active file.
lines The range of lines currently selected in the editor (start and end). If no lines are selected, this value is null.
timestamp The timestamp of the last update in ISO format (e.g., 2025-01-07T20:00:00Z).
language The language mode of the active file (e.g., javascript, python, go).
workspace The path to the root of your open workspace.
fileSize The size of the file in bytes.
lastModified The last modified timestamp of the active file in ISO format.

How It Works

  1. Automatic Updates:

    • The fileMetadata.json file is automatically updated whenever you:
      • Open a new file.
      • Switch between files.
      • Highlight or select lines in a file.
  2. Command: Current File Tracker:

    • Manually trigger metadata updates using the Command Palette:
      • Open the Command Palette (Cmd+Shift+P or Ctrl+Shift+P).
      • Search for and select Current File Tracker.
    • This is useful if you want to ensure metadata is updated on-demand.

Example fileMetadata.json

Here’s an example of what the fileMetadata.json file might look like:

{
    "fileName": "example.js",
    "filePath": "/Users/example/project/example.js",
    "lines": {
        "start": 5,
        "end": 15
    },
    "timestamp": "2025-01-07T20:00:00Z",
    "language": "javascript",
    "workspace": "/Users/example/project",
    "fileSize": 1456,
    "lastModified": "2025-01-07T19:45:00Z"
}

Usage Instructions

  1. Install the extension in VSCode:

    • Install the .vsix file through the Extensions view in VSCode or download it from the Marketplace.
  2. Run the command once:

    • Run the Current File Tracker command once from the Command Palette (Cmd+Shift+P or Ctrl+Shift+P)
  3. Open any file in your editor:

    • The extension will automatically detect the active file and start updating metadata.
  4. Start working:

    • The fileMetadata.json file will be automatically updated whenever you open a file or select text in the editor.

Notes

  1. Add fileMetadata.json to .gitignore:
    • To avoid tracking workspace-specific metadata in your version control system, add the following line to your .gitignore file:
      fileMetadata.json
      

License

This extension is open-source and available under the MIT License. See the LICENSE file for details.


Contributing

Contributions are welcome! If you'd like to contribute, please open an issue or submit a pull request on GitHub.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft