Skip to content

Commit

Permalink
Bug fixes (OpenNingia#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
fr43nk authored Aug 2, 2022
1 parent 3ad1f22 commit 90c2cae
Show file tree
Hide file tree
Showing 21 changed files with 1,298 additions and 1,196 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"bracketSameLine": true,
"printWidth": 120
}
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
"prettier.enable": true,
"editor.formatOnSave": true
}
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-clearcase",
"displayName": "Unofficial ClearCase SCM Commands",
"description": "Unofficial support for IBM Rational ClearCase most common commands",
"version": "4.1.0",
"version": "4.1.1-rc.5",
"publisher": "OpenNingia",
"license": "MIT",
"repository": {
Expand Down
187 changes: 96 additions & 91 deletions src/ccAnnotateController.ts
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() {}
}
16 changes: 6 additions & 10 deletions src/ccAnnotateLens.ts
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);
}
}
88 changes: 43 additions & 45 deletions src/ccAnnotateLensProvider.ts
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);
}
}
Loading

0 comments on commit 90c2cae

Please sign in to comment.