-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a simple extension to show timestamps (#1094)
- Loading branch information
Showing
17 changed files
with
924 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters