Skip to content
Draft
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
48 changes: 25 additions & 23 deletions src/codeowners-hover-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import vscode from "vscode"
import { dirname } from "path"
import fs from "fs"

export class CodeownersHoverProvider implements vscode.HoverProvider {
provideHover(
Expand All @@ -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),
Expand All @@ -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")],
}
}
}
Loading