Skip to content

Commit

Permalink
feat: Add a simple extension to show timestamps (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jan 5, 2025
1 parent 71dd442 commit e616e46
Show file tree
Hide file tree
Showing 17 changed files with 924 additions and 0 deletions.
2 changes: 2 additions & 0 deletions extensions/timestamp-hover/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
node_modules
28 changes: 28 additions & 0 deletions extensions/timestamp-hover/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "${workspaceRoot}/samples"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "npm: build"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
"preLaunchTask": "npm: build"
}
]
}
38 changes: 38 additions & 0 deletions extensions/timestamp-hover/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "npm: build",
"type": "npm",
"script": "build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$tsc"
},
{
"label": "npm: clean-build",
"type": "npm",
"script": "clean-build",
"problemMatcher": "$tsc"
},
{
"label": "npm: test",
"type": "npm",
"script": "test",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "npm: watch",
"type": "npm",
"script": "watch",
"problemMatcher": ["$tsc-watch"]
}
]
}
8 changes: 8 additions & 0 deletions extensions/timestamp-hover/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**/*
!LICENSE
!README.md
!images/Screenshot1.png
!images/icon.jpg
!package.json
!CHANGELOG.md
!out/**/*.js
Empty file.
691 changes: 691 additions & 0 deletions extensions/timestamp-hover/LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions extensions/timestamp-hover/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Timestamp Hover

Display the ISO time and date while hovering over timestamps.

- Automatically converts timestamps from seconds, milliseconds, or microseconds to ISO Time.
- Does not coverts timestamps before 1980 to avoid being noisy.

![Example](./images/Screenshot1.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extensions/timestamp-hover/images/icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extensions/timestamp-hover/images/icon.orig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions extensions/timestamp-hover/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions extensions/timestamp-hover/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "timestamp-hover",
"displayName": "Timestamp Hover",
"description": "Display the date and time of a timestamp.",
"icon": "images/icon.jpg",
"version": "0.1.0",
"private": true,
"publisher": "streetsidesoftware",
"license": "GPL-3.0-or-later",
"type": "commonjs",
"engines": {
"vscode": "^1.67.0"
},
"sponsor": {
"url": "https://github.com/sponsors/streetsidesoftware"
},
"extensionKind": [
"ui", "workspace"
],
"categories": [
"Other"
],
"activationEvents": [
"onStartupFinished"
],
"qna": "marketplace",
"main": "./out/extension.js",
"browser": "./out/extension.js",
"capabilities": {
"virtualWorkspaces": true,
"untrustedWorkspaces": {
"supported": true
}
},
"contributes": {},
"repository": {
"type": "git",
"url": "https://github.com/streetsidesoftware/vscode-cspell-dict-extensions",
"directory": "extensions/timestamp-hover"
},
"bugs": {
"url": "https://github.com/streetsidesoftware/vscode-cspell-dict-extensions/issues"
},
"scripts": {
"clean": "rimraf out *.vsix",
"clean-build": "npm run clean && npm run build",
"prepublishOnly": "echo prepublishOnly",
"publish-extension": "vsce publish",
"pack-extension": "vsce package",
"vscode:prepublish": "npm run build",
"build": "tsc -p ./",
"watch": "tsc -watch -p ./",
"test:cspell": "cspell .",
"test:vscode": "echo OK",
"test": "npm run test:cspell && npm run test:vscode"
},
"dependencies": {
}
}
9 changes: 9 additions & 0 deletions extensions/timestamp-hover/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Medical Terms

Some example medical terms.

---

abiana abiate abiatrophy abiatus abid abidi abidochromis abience abient abietene abietic abietine abietite abigeat abigei Abilify abinoxylan abio AbioCor abiogeneses abiogenesis abiogenetic abiogenic abiogenist abiogenous abiogeny Abiological Abiomed AbioMed abionergy abioseston abiosis abiotic abiotically

ZUMI Zung Zunrisa Zuntz's Zuplenz Zweifel zwitterion Zyban Zybit Zyderm Zydis Zydone Zyflo zygal zygapophyseal zygapophyseales zygapophysial zygapophysiales zygapophysis zygia zygion Zygocotyle zygodactyly zygoma zygomas zygomatic zygomatica zygomatici zygomatico zygomaticoauricular zygomaticofacial zygomaticofacialis zygomaticofrontal zygomaticofrontalis zygomaticomaxillaris zygomaticomaxillary zygomaticosphenoid zygomaticotemporal zygomaticotemporalis
1 change: 1 addition & 0 deletions extensions/timestamp-hover/samples/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
53 changes: 53 additions & 0 deletions extensions/timestamp-hover/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
const options: FormatTimestampOptions = {
minDate: new Date('1980-01-01'),
}

const hoverProvider = vscode.languages.registerHoverProvider({ scheme: '*', language: '*' }, {
provideHover(document, position) {
const range = document.getWordRangeAtPosition(position);
if (!range) {
return undefined;
}
const word = document.getText(range);
const hoverMessage = formatTimestamp(word, options);
return hoverMessage ? new vscode.Hover(`_${hoverMessage}_`) : undefined;
}
});
context.subscriptions.push(hoverProvider);
}

const regexpIsNumber = /^\d+$/;

interface FormatTimestampOptions {
minDate: Date;
}

function formatTimestamp(text: string, options: FormatTimestampOptions): string | undefined {
if (!regexpIsNumber.test(text)) {
return undefined;
}
let timestamp = Number(text);
if (timestamp < 1e11) {
// seconds to milliseconds
timestamp *= 1000;
}
if (timestamp > 1e14) {
// microseconds to milliseconds
timestamp /= 1000;
}
if (timestamp < options.minDate.getTime()) {
return undefined;
}
return new Date(timestamp).toISOString();
}


// this method is called when your extension is deactivated
export function deactivate() {}
8 changes: 8 additions & 0 deletions extensions/timestamp-hover/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "out"
},
"include": ["src", "test"],
"exclude": ["out", "node_modules", ".vscode-test"]
}
3 changes: 3 additions & 0 deletions static/dictionary-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
],
"Syntax Highlighters": [
"extensions/hunspell-syntax"
],
"Other": [
"extensions/timestamp-hover"
]
},
"default": "Languages"
Expand Down

0 comments on commit e616e46

Please sign in to comment.