Skip to content

Commit

Permalink
Merge pull request #28 from bmalehorn/lens-collision
Browse files Browse the repository at this point in the history
decorations: prevent interference from other lens extensions
  • Loading branch information
usernamehw authored Oct 9, 2019
2 parents bd82f4f + 901051c commit a1fd530
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function activate(context: vscode.ExtensionContext): void {
let configHintEnabled = true;
let lastSavedTimestamp = Date.now() + 5000;

let decorationRenderOptionsError: vscode.DecorationRenderOptions;
let decorationRenderOptionsWarning: vscode.DecorationRenderOptions;
let decorationRenderOptionsInfo: vscode.DecorationRenderOptions;
let decorationRenderOptionsHint: vscode.DecorationRenderOptions;

let decorationTypeError: vscode.TextEditorDecorationType;
let decorationTypeWarning: vscode.TextEditorDecorationType;
let decorationTypeInfo: vscode.TextEditorDecorationType;
Expand Down Expand Up @@ -224,10 +229,21 @@ export function activate(context: vscode.ExtensionContext): void {
}
}
}

let decorationRenderOptions: vscode.DecorationRenderOptions = {};
switch (aggregatedDiagnostic[0].severity) {
case 0: decorationRenderOptions = decorationRenderOptionsError; break;
case 1: decorationRenderOptions = decorationRenderOptionsWarning; break;
case 2: decorationRenderOptions = decorationRenderOptionsInfo; break;
case 3: decorationRenderOptions = decorationRenderOptionsHint; break;
}

// Generate a DecorationInstanceRenderOptions object which specifies the text which will be rendered
// after the source-code line in the editor
const decInstanceRenderOptions: vscode.DecorationInstanceRenderOptions = {
...decorationRenderOptions,
after: {
...decorationRenderOptions.after || {},
contentText: truncate(messagePrefix + aggregatedDiagnostic[0].message),
},
};
Expand Down Expand Up @@ -418,7 +434,7 @@ export function activate(context: vscode.ExtensionContext): void {
textDecoration: `;${fontFamily};${fontSize};${paddingAndBorderRadius};margin-left:${onlyDigitsRegExp.test(config.margin) ? `${config.margin}px` : config.margin};`,
};

decorationTypeError = window.createTextEditorDecorationType({
decorationRenderOptionsError = {
backgroundColor: config.errorBackground,
gutterIconSize: errorGutterIconSizeAndColor,
gutterIconPath: errorGutterIconPath,
Expand All @@ -436,8 +452,8 @@ export function activate(context: vscode.ExtensionContext): void {
},
},
isWholeLine: true,
});
decorationTypeWarning = window.createTextEditorDecorationType({
};
decorationRenderOptionsWarning = {
backgroundColor: config.warningBackground,
gutterIconSize: warningGutterIconSizeAndColor,
gutterIconPath: warningGutterIconPath,
Expand All @@ -455,8 +471,8 @@ export function activate(context: vscode.ExtensionContext): void {
},
},
isWholeLine: true,
});
decorationTypeInfo = window.createTextEditorDecorationType({
};
decorationRenderOptionsInfo = {
backgroundColor: config.infoBackground,
gutterIconSize: infoGutterIconSizeAndColor,
gutterIconPath: infoGutterIconPath,
Expand All @@ -474,8 +490,8 @@ export function activate(context: vscode.ExtensionContext): void {
},
},
isWholeLine: true,
});
decorationTypeHint = window.createTextEditorDecorationType({
};
decorationRenderOptionsHint = {
backgroundColor: config.hintBackground,
after: {
...afterProps,
Expand All @@ -489,7 +505,12 @@ export function activate(context: vscode.ExtensionContext): void {
},
},
isWholeLine: true,
});
};

decorationTypeError = window.createTextEditorDecorationType(decorationRenderOptionsError);
decorationTypeWarning = window.createTextEditorDecorationType(decorationRenderOptionsWarning);
decorationTypeInfo = window.createTextEditorDecorationType(decorationRenderOptionsInfo);
decorationTypeHint = window.createTextEditorDecorationType(decorationRenderOptionsHint);
}

function updateEverything(): void {
Expand Down

0 comments on commit a1fd530

Please sign in to comment.