-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
197 additions
and
158 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
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,44 @@ | ||
import { commands, Disposable, OutputChannel, window } from 'vscode'; | ||
|
||
import StatusBarService from './StatusBarService'; | ||
|
||
import { EXTENSION_NAME } from './utils'; | ||
|
||
class LoggingService { | ||
private outputChannel: OutputChannel; | ||
private statusbarService: StatusBarService; | ||
|
||
constructor(statusbarService: StatusBarService) { | ||
this.outputChannel = window.createOutputChannel(EXTENSION_NAME); | ||
this.statusbarService = statusbarService; | ||
} | ||
|
||
// add message to the output channel | ||
public addToOutput(message: string): void { | ||
const title = `${new Date().toLocaleString()}:`; | ||
|
||
// Create a sort of title, to differentiate between messages | ||
this.outputChannel.appendLine(title); | ||
this.outputChannel.appendLine('-'.repeat(title.length)); | ||
|
||
// Append actual output | ||
this.outputChannel.appendLine(`${message}\n`); | ||
} | ||
|
||
public registerDisposables(): Disposable[] { | ||
return [ | ||
commands.registerCommand('scss-formatter.open-output', () => { | ||
this.outputChannel.show(); | ||
}), | ||
commands.registerCommand('scss-formatter.show-output', () => { | ||
this.outputChannel.show(); | ||
}), | ||
commands.registerCommand('scss-formatter.clear-output', () => { | ||
this.outputChannel.clear(); | ||
this.statusbarService.reset(); | ||
}) | ||
]; | ||
} | ||
} | ||
|
||
export default LoggingService; |
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,65 @@ | ||
import { | ||
Disposable, languages, StatusBarAlignment, | ||
StatusBarItem, TextEditor, window | ||
} from 'vscode'; | ||
|
||
import { EXTENSION_NAME, EXTENSION_VERSION, supportedLanguages } from './utils'; | ||
|
||
function checkForInConsoleTabSwitch(editor: TextEditor): boolean { | ||
// output and debug console is also seen as an editor | ||
// hence switching tabs will trigger the function | ||
// this prevents hiding statusBarItem when switching between tabs | ||
return ['debug', 'output'].some( | ||
(part) => editor.document.uri.scheme === part); | ||
} | ||
|
||
class StatusBarService { | ||
private statusBarItem: StatusBarItem; | ||
|
||
constructor() { | ||
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, -1); | ||
this.statusBarItem.text = EXTENSION_NAME; | ||
this.statusBarItem.tooltip = `${EXTENSION_NAME}: v${EXTENSION_VERSION}`; | ||
this.statusBarItem.command = 'scss-formatter.open-output'; | ||
|
||
this.toggleStatusBarItem(window.activeTextEditor); | ||
} | ||
|
||
public registerDisposables(): Disposable[] { | ||
return [ | ||
// Keep track whether to show/hide the statusbar | ||
window.onDidChangeActiveTextEditor((editor: TextEditor | undefined) => { | ||
this.toggleStatusBarItem(editor); | ||
}) | ||
]; | ||
} | ||
|
||
// toggle statusBarItem when document changes | ||
private toggleStatusBarItem(editor: TextEditor | undefined): void { | ||
if (!this.statusBarItem) { | ||
return; | ||
} | ||
|
||
if (editor !== undefined) { | ||
if (checkForInConsoleTabSwitch(editor)) { return; } | ||
|
||
// hide statusBarItem if document changes and doesn't match supported languages | ||
const score = languages.match(supportedLanguages, editor.document); | ||
score ? this.statusBarItem.show() : this.statusBarItem.hide(); | ||
} else { | ||
this.statusBarItem.hide(); | ||
} | ||
} | ||
|
||
// update statusBarItem text and tooltip | ||
public updateStatusBarItem(message: string): void { | ||
this.statusBarItem.text = message; | ||
this.statusBarItem.show(); | ||
} | ||
|
||
public reset() { | ||
this.statusBarItem.text = EXTENSION_NAME; | ||
} | ||
} | ||
|
||
export default StatusBarService; |
This file was deleted.
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