forked from OpenNingia/vscode-clearcase
-
Notifications
You must be signed in to change notification settings - Fork 0
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
21 changed files
with
1,298 additions
and
1,196 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,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true, | ||
"bracketSameLine": true, | ||
"printWidth": 120 | ||
} |
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
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
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 |
---|---|---|
@@ -1,100 +1,105 @@ | ||
'use strict'; | ||
|
||
import * as vscode from 'vscode'; | ||
import { CCConfigHandler } from './ccConfigHandler'; | ||
import { CCConfiguration } from './ccConfiguration'; | ||
import { | ||
DecorationOptions, | ||
DecorationRenderOptions, | ||
ExtensionContext, | ||
Range, | ||
TextEditor, | ||
TextEditorDecorationType, | ||
window, | ||
} from "vscode"; | ||
import { CCConfigHandler } from "./ccConfigHandler"; | ||
import { CCConfiguration } from "./ccConfiguration"; | ||
|
||
export class CCAnnotationController { | ||
private mDecorationType: vscode.TextEditorDecorationType; | ||
private mIsActive: boolean; | ||
private mConfiguration: CCConfiguration; | ||
|
||
constructor( | ||
private editor: vscode.TextEditor, | ||
private context: vscode.ExtensionContext, | ||
private configHandler: CCConfigHandler) { | ||
this.mIsActive = false; | ||
vscode.window.onDidChangeActiveTextEditor(this.onActiveEditorChange, this, this.context.subscriptions); | ||
this.configHandler.onDidChangeConfiguration(this.onConfigurationChanged, this); | ||
let ro: vscode.DecorationRenderOptions = { | ||
isWholeLine: false, | ||
before: { | ||
margin: '0 1em 0 0' | ||
}, | ||
after: { | ||
margin: '0 0 0 1em' | ||
} | ||
}; | ||
this.mDecorationType = vscode.window.createTextEditorDecorationType(ro); | ||
this.mConfiguration = this.configHandler.configuration; | ||
} | ||
private mDecorationType: TextEditorDecorationType; | ||
private mIsActive: boolean; | ||
private mConfiguration: CCConfiguration; | ||
|
||
onActiveEditorChange(event: vscode.TextEditor|undefined): any { | ||
if (event) { | ||
this.mIsActive = false; | ||
this.editor = event; | ||
} | ||
} | ||
constructor(private editor: TextEditor, private context: ExtensionContext, private configHandler: CCConfigHandler) { | ||
this.mIsActive = false; | ||
window.onDidChangeActiveTextEditor(this.onActiveEditorChange, this, this.context.subscriptions); | ||
this.configHandler.onDidChangeConfiguration(this.onConfigurationChanged, this); | ||
let ro: DecorationRenderOptions = { | ||
isWholeLine: false, | ||
before: { | ||
margin: "0 1em 0 0", | ||
}, | ||
after: { | ||
margin: "0 0 0 1em", | ||
}, | ||
}; | ||
this.mDecorationType = window.createTextEditorDecorationType(ro); | ||
this.mConfiguration = this.configHandler.configuration; | ||
} | ||
|
||
onConfigurationChanged() { | ||
this.mConfiguration = this.configHandler.configuration; | ||
} | ||
onActiveEditorChange(event: TextEditor | undefined): any { | ||
if (event) { | ||
this.mIsActive = false; | ||
this.editor = event; | ||
} | ||
} | ||
|
||
setAnnotationInText(annotationText: string) { | ||
let deco: vscode.DecorationOptions[] = []; | ||
let maxWidth: number = 0; | ||
if (this.mIsActive === false) { | ||
let textLines = annotationText.split(/[\n\r]+/); | ||
let textLineParts = textLines.map(l => { | ||
let parts = l.split(" | "); | ||
parts[0] = parts[0].replace(/\\/g, "/"); | ||
if (parts[0].length > maxWidth) { | ||
maxWidth = parts[0].length; | ||
} | ||
return parts; | ||
}); | ||
deco = this.getDecoration(textLineParts, maxWidth); | ||
this.mIsActive = true; | ||
} | ||
else { | ||
this.mIsActive = false; | ||
} | ||
this.editor.setDecorations(this.mDecorationType, deco); | ||
} | ||
onConfigurationChanged() { | ||
this.mConfiguration = this.configHandler.configuration; | ||
} | ||
|
||
getDecoration(iLines: string[][], iMaxWidth: number): vscode.DecorationOptions[] { | ||
let max: number = 0; | ||
let deco: vscode.DecorationOptions[] = []; | ||
for (let lineNr = 0; lineNr < iLines.length; lineNr++) { | ||
let line = iLines[lineNr][0].replace(/ /gi, '\u00A0'); | ||
while (line.length < iMaxWidth) { | ||
line = line.concat('\u00A0'); | ||
} | ||
deco.push(this.createLineDecoration(line, lineNr, 0, max)); | ||
} | ||
return deco; | ||
} | ||
setAnnotationInText(annotationText: string) { | ||
let deco: DecorationOptions[] = []; | ||
let maxWidth: number = 0; | ||
if (this.mIsActive === false) { | ||
let textLines = annotationText.split(/[\n\r]+/); | ||
let textLineParts = textLines.map((l) => { | ||
let parts = l.split(" | "); | ||
parts[0] = parts[0].replace(/\\/g, "/"); | ||
if (parts[0].length > maxWidth) { | ||
maxWidth = parts[0].length; | ||
} | ||
return parts; | ||
}); | ||
deco = this.getDecoration(textLineParts, maxWidth); | ||
this.mIsActive = true; | ||
} else { | ||
this.mIsActive = false; | ||
} | ||
this.editor.setDecorations(this.mDecorationType, deco); | ||
} | ||
|
||
private createLineDecoration(iLinePart: string, iLineNr: number, iCharStart: number, iWidth: number): vscode.DecorationOptions { | ||
let charLen = iLinePart.length; | ||
let range = vscode.window.activeTextEditor?.document.validateRange(new vscode.Range(iLineNr, iCharStart, iLineNr, charLen)); | ||
if( range === undefined ) { | ||
range = new vscode.Range(0,0,0,0); | ||
} | ||
return { | ||
hoverMessage: "", | ||
range: range, | ||
renderOptions: { | ||
before: { | ||
color: this.mConfiguration.annotationColor.value, | ||
backgroundColor: this.mConfiguration.annotationBackground.value, | ||
contentText: iLinePart | ||
} | ||
} | ||
}; | ||
} | ||
getDecoration(iLines: string[][], iMaxWidth: number): DecorationOptions[] { | ||
let max: number = 0; | ||
let deco: DecorationOptions[] = []; | ||
for (let lineNr = 0; lineNr < iLines.length; lineNr++) { | ||
let line = iLines[lineNr][0].replace(/ /gi, "\u00A0"); | ||
while (line.length < iMaxWidth) { | ||
line = line.concat("\u00A0"); | ||
} | ||
deco.push(this.createLineDecoration(line, lineNr, 0, max)); | ||
} | ||
return deco; | ||
} | ||
|
||
dispose() { | ||
private createLineDecoration( | ||
iLinePart: string, | ||
iLineNr: number, | ||
iCharStart: number, | ||
iWidth: number | ||
): DecorationOptions { | ||
let charLen = iLinePart.length; | ||
let range = window.activeTextEditor?.document.validateRange(new Range(iLineNr, iCharStart, iLineNr, charLen)); | ||
if (range === undefined) { | ||
range = new Range(0, 0, 0, 0); | ||
} | ||
return { | ||
hoverMessage: "", | ||
range: range, | ||
renderOptions: { | ||
before: { | ||
color: this.mConfiguration.annotationColor.value, | ||
backgroundColor: this.mConfiguration.annotationBackground.value, | ||
contentText: iLinePart, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
} | ||
} | ||
dispose() {} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
'use strict'; | ||
import { CodeLens, Range, TextDocument } from "vscode"; | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
export class CCAnnotateLens extends vscode.CodeLens | ||
{ | ||
constructor(public document: vscode.TextDocument, range: vscode.Range) | ||
{ | ||
super(range); | ||
} | ||
} | ||
export class CCAnnotateLens extends CodeLens { | ||
constructor(public document: TextDocument, range: Range) { | ||
super(range); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,51 +1,49 @@ | ||
import * as vscode from 'vscode'; | ||
import {CCAnnotateLens} from './ccAnnotateLens'; | ||
import {CCConfigHandler} from './ccConfigHandler'; | ||
import { CCScmProvider } from './ccScmProvider'; | ||
import { CancellationToken, CodeLens, CodeLensProvider, ExtensionContext, Range, TextDocument } from "vscode"; | ||
import { CCAnnotateLens } from "./ccAnnotateLens"; | ||
import { CCConfigHandler } from "./ccConfigHandler"; | ||
import { CCScmProvider } from "./ccScmProvider"; | ||
|
||
export class CCCodeLensProvider implements vscode.CodeLensProvider | ||
{ | ||
static selector = { | ||
scheme: "file" | ||
}; | ||
export class CCCodeLensProvider implements CodeLensProvider { | ||
static selector = { | ||
scheme: "file", | ||
}; | ||
|
||
public constructor(private mContext: vscode.ExtensionContext, private mCfg: CCConfigHandler, private mProvider: CCScmProvider) | ||
{ | ||
} | ||
public constructor( | ||
private mContext: ExtensionContext, | ||
private mCfg: CCConfigHandler, | ||
private mProvider: CCScmProvider | ||
) {} | ||
|
||
public provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Thenable<vscode.CodeLens[]> | vscode.CodeLens[] | ||
{ | ||
if ( !this.mCfg.configuration.showAnnotationCodeLens.value ) { | ||
return []; | ||
} | ||
|
||
let lLenses: vscode.CodeLens[] = []; | ||
return new Promise(resolve => { | ||
this.mProvider.clearCase?.isClearcaseObject(document.uri).then((is:boolean) => { | ||
if( document !== undefined && is === true ) { | ||
lLenses.push(new CCAnnotateLens(document, new vscode.Range(0,0,0,1))); | ||
} | ||
resolve(lLenses); | ||
}); | ||
}); | ||
} | ||
public provideCodeLenses(document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> | CodeLens[] { | ||
if (!this.mCfg.configuration.showAnnotationCodeLens.value) { | ||
return []; | ||
} | ||
|
||
public resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken): Thenable<vscode.CodeLens> | ||
{ | ||
if( codeLens instanceof CCAnnotateLens ) { | ||
return this.ccAnnotationCommand(codeLens, token); | ||
} | ||
let lLenses: CodeLens[] = []; | ||
return new Promise((resolve) => { | ||
this.mProvider.clearCase?.isClearcaseObject(document.uri).then((is: boolean) => { | ||
if (document !== undefined && is === true) { | ||
lLenses.push(new CCAnnotateLens(document, new Range(0, 0, 0, 1))); | ||
} | ||
resolve(lLenses); | ||
}); | ||
}); | ||
} | ||
|
||
return Promise.reject<vscode.CodeLens>(undefined); | ||
} | ||
public resolveCodeLens(codeLens: CodeLens, token: CancellationToken): Thenable<CodeLens> { | ||
if (codeLens instanceof CCAnnotateLens) { | ||
return this.ccAnnotationCommand(codeLens, token); | ||
} | ||
|
||
private ccAnnotationCommand(iLens: CCAnnotateLens, iToken: vscode.CancellationToken) | ||
{ | ||
iLens.command = { | ||
title: "Toggle annotations", | ||
command: "extension.ccAnnotate", | ||
arguments: [iLens.document.uri] | ||
}; | ||
return Promise.resolve(iLens); | ||
} | ||
} | ||
return Promise.reject<CodeLens>(undefined); | ||
} | ||
|
||
private ccAnnotationCommand(iLens: CCAnnotateLens, iToken: CancellationToken) { | ||
iLens.command = { | ||
title: "Toggle annotations", | ||
command: "extension.ccAnnotate", | ||
arguments: [iLens.document.uri], | ||
}; | ||
return Promise.resolve(iLens); | ||
} | ||
} |
Oops, something went wrong.