Skip to content

Commit 7b99ede

Browse files
authored
0.1.6: Add Logging
1 parent fe3a6da commit 7b99ede

4 files changed

Lines changed: 62 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Change Log
22

3+
## 0.1.6
4+
- Added logging to help debug some issues.
35

46
## 0.1.5
57
- Made the shortcut position in the editor context menu configurable by setting `manpages.editorMenuShortcutPosition`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Manpages",
44
"publisher": "meronz",
55
"description": "Quickly open man pages and navigate through them.",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"icon": "media/logo.png",
88
"author": {
99
"name": "Salvatore Merone"

src/logging.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2023 Salvatore Merone
2+
//
3+
// This file is part of vscode.manpages.
4+
//
5+
// vscode.manpages is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// vscode.manpages is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with vscode.manpages. If not, see <http://www.gnu.org/licenses/>.
17+
18+
import {ExtensionContext, window, OutputChannel, Range, Selection, Position} from 'vscode';
19+
20+
const LoggingChannelName = 'Manpages';
21+
22+
export class Logging {
23+
private static _channel: OutputChannel;
24+
25+
constructor(context: ExtensionContext) {
26+
if(!Logging._channel) {
27+
Logging._channel = window.createOutputChannel(LoggingChannelName);
28+
context.subscriptions.push(Logging._channel);
29+
}
30+
}
31+
32+
public log(message: string): void {
33+
Logging._channel.appendLine(message);
34+
}
35+
36+
public printRange(range: Range): string {
37+
return `${this.printPosition(range.start)}-${this.printPosition(range.end)}`;
38+
}
39+
40+
public printSelection(selection: Selection): string {
41+
return `${this.printPosition(selection.start)}-${this.printPosition(selection.end)}`;
42+
}
43+
44+
public printPosition(position: Position): string {
45+
return `${position.line}:${position.character}`;
46+
}
47+
}

src/manpageContentProvider.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import * as vscode from 'vscode';
1919
import { MAN_COMMAND_REGEX } from './consts';
2020
import ManpageDocument from './manpageDocument';
2121
import child_process = require('child_process');
22+
import { Logging } from './logging';
2223

2324
export class ManpageContentView {
2425
constructor(context: vscode.ExtensionContext) {
25-
26-
const provider = new ManpageContentProvider();
26+
const logger = new Logging(context);
27+
const provider = new ManpageContentProvider(context);
2728

2829
// register content provider
2930
const providerRegistrations = vscode.Disposable.from(
@@ -35,16 +36,20 @@ export class ManpageContentView {
3536

3637

3738
const openFromSelection = vscode.commands.registerTextEditorCommand('manpages.openFromSelection', (editor) => {
39+
logger.log(`openFromSelection called with selection: ${editor.selection.isEmpty ? 'empty' : 'not empty'}`);
3840
if (editor.selection.isEmpty) return;
3941
let text = editor.document.getText(editor.selection);
42+
logger.log(`openFromSelection selection: ${logger.printSelection(editor.selection)}, text: ${text}`);
4043
return openManPage(text, openInActiveColumn);
4144
});
4245

4346
const openFromCursor = vscode.commands.registerTextEditorCommand('manpages.openFromCursor', (editor) => {
47+
logger.log(`openFromCursor called with selection: ${editor.selection.isEmpty ? 'empty' : 'not empty'}`);
4448
if (!editor.selection.isEmpty) return;
4549
const wordRange = editor.document.getWordRangeAtPosition(editor.selection.active, MAN_COMMAND_REGEX);
4650
if (!wordRange) { return; }
4751
let text = editor.document.getText(wordRange);
52+
logger.log(`openFromCursor wordRange: ${logger.printRange(wordRange)}, text: ${text}`);
4853
return openManPage(text, openInActiveColumn);
4954
});
5055

@@ -57,6 +62,7 @@ export class ManpageContentView {
5762
}
5863
});
5964

65+
logger.log(`openFromInput called with text: ${result}`);
6066
if (result) {
6167
return openManPage(result, openInActiveColumn);
6268
}
@@ -78,12 +84,13 @@ export class ManpageContentProvider implements vscode.TextDocumentContentProvide
7884
private _documents = new Map<string, ManpageDocument>();
7985
private _editorDecoration = vscode.window.createTextEditorDecorationType({ textDecoration: 'underline' });
8086
private _subscriptions: vscode.Disposable;
87+
private _logger: Logging;
8188

82-
constructor() {
83-
89+
constructor(context: vscode.ExtensionContext) {
8490
// Listen to the `closeTextDocument`-event which means we must
8591
// clear the corresponding model object - `ReferencesDocument`
8692
this._subscriptions = vscode.workspace.onDidCloseTextDocument(doc => this._documents.delete(doc.uri.toString()));
93+
this._logger = new Logging(context);
8794
}
8895

8996
dispose(): void {
@@ -118,6 +125,7 @@ export class ManpageContentProvider implements vscode.TextDocumentContentProvide
118125
let section = m[2];
119126

120127
let cmd = this.buildCmdline(section, word);
128+
this._logger.log(`Executing command: ${cmd}`);
121129

122130
return new Promise((resolve) => {
123131
child_process.exec(cmd, (err, stdout, stderr) => {

0 commit comments

Comments
 (0)