diff --git a/CHANGELOG.md b/CHANGELOG.md index 26da346..b4d4ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 4.2.0 - 2026-03-14 + +### Changed + +- Adjust hover text for substring vs full path matches (#). + ## 4.1.0 - 2024-04-13 ### Changed diff --git a/package.json b/package.json index ece2ea5..42e9f51 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Quickly see GitHub Code Owners for the current file. Add syntax highlighting for CODEOWNERS files.", "publisher": "chdsbd", "license": "SEE LICENSE IN LICENSE", - "version": "4.1.0", + "version": "4.2.0", "icon": "images/logo256.png", "homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md", "keywords": [ diff --git a/src/codeowners-hover-provider.ts b/src/codeowners-hover-provider.ts index 1d112a3..5330e4d 100644 --- a/src/codeowners-hover-provider.ts +++ b/src/codeowners-hover-provider.ts @@ -1,6 +1,4 @@ import vscode from "vscode" -import { dirname } from "path" -import fs from "fs" export class CodeownersHoverProvider implements vscode.HoverProvider { provideHover( @@ -14,22 +12,12 @@ export class CodeownersHoverProvider implements vscode.HoverProvider { } const idx = line.text.indexOf(m) - const workspaceDir = dirname(dirname(document.uri.fsPath)) - const myPath = workspaceDir + "/" + m - - let isDirectory: boolean | null = null - try { - isDirectory = fs.statSync(myPath).isDirectory() - } catch (e) { - // @ts-expect-error we should see this error. - if (e.code !== "ENOENT") { - console.error("github-code-owners", e) - } - } const x = new vscode.MarkdownString() x.appendCodeblock(m) - const isPattern = !m.startsWith("/") + const hasLeadingSlash = m.startsWith("/") + const hasTrailingSlash = m.endsWith("/") + const hasTrailingGlob = m.endsWith("/*") const range = new vscode.Range( new vscode.Position(position.line, idx), @@ -38,16 +26,30 @@ export class CodeownersHoverProvider implements vscode.HoverProvider { if (!range.contains(position)) { return { contents: [] } } + + const lines: string[] = [] + + if (hasLeadingSlash) { + lines.push("**Anchored to repo root** — only matches at the top level") + } else { + lines.push( + "**Matches at any depth** — applies to this path anywhere in the repository)", + ) + } + + if (hasTrailingGlob) { + lines.push( + "**Shallow match** — covers only direct children, not subdirectories", + ) + } else if (hasTrailingSlash) { + lines.push( + "**Recursive directory match** — covers the directory and all its contents at any depth", + ) + } + return { range, - contents: [ - x, - isPattern - ? "Matches all files with same name" - : isDirectory - ? `Matches all files in directory and subdirectories` - : `Matches path exactly`, - ], + contents: [x, lines.join("\n\n")], } } }