|
1 |
| -import { CodeLensProvider, TextDocument, CodeLens, CancellationToken, workspace } from 'vscode'; |
2 |
| -import { CodeMetricsCodeLens } from '../models/CodeMetricsCodeLens'; |
3 |
| -import { IMetricsModel } from 'tsmetrics-core'; |
4 |
| -import { MetricsUtil } from "../metrics/MetricsUtil"; |
5 |
| - |
6 |
| -export class CodeMetricsCodeLensProvider implements CodeLensProvider { |
7 |
| - private metricsUtil: MetricsUtil; |
8 |
| - |
9 |
| - constructor(metricsUtil: MetricsUtil) { |
10 |
| - this.metricsUtil = metricsUtil; |
11 |
| - } |
12 |
| - |
13 |
| - provideCodeLenses(document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> { |
14 |
| - if (!this.metricsUtil.appConfig.codeMetricsDisplayed) return; |
15 |
| - if (!this.metricsUtil.appConfig.codeMetricsSettings.CodeLensEnabled) return; |
16 |
| - return this.metricsUtil.getMetrics(document).then(metrics => { |
17 |
| - const result: CodeLens[] = metrics.map(model => new CodeMetricsCodeLens(model, this.metricsUtil.toRange(model, document))) |
18 |
| - return result; |
19 |
| - }); |
20 |
| - } |
21 |
| - |
22 |
| - resolveCodeLens(codeLens: CodeLens, token: CancellationToken): CodeLens { |
23 |
| - if (codeLens instanceof CodeMetricsCodeLens) { |
24 |
| - codeLens.command = { |
25 |
| - title: this.metricsUtil.format(codeLens), |
26 |
| - command: "codemetrics.showCodeMetricsCodeLensInfo", |
27 |
| - arguments: [codeLens] |
28 |
| - }; |
29 |
| - return codeLens; |
30 |
| - } |
31 |
| - return null; |
32 |
| - } |
33 |
| -} |
| 1 | +import { CodeLensProvider, TextDocument, CodeLens, CancellationToken, workspace } from "vscode"; |
| 2 | +import { CodeMetricsCodeLens } from "../models/CodeMetricsCodeLens"; |
| 3 | +import { IMetricsModel } from "tsmetrics-core"; |
| 4 | +import { MetricsUtil } from "../metrics/MetricsUtil"; |
| 5 | + |
| 6 | +export class CodeMetricsCodeLensProvider implements CodeLensProvider { |
| 7 | + private metricsUtil: MetricsUtil; |
| 8 | + |
| 9 | + constructor(metricsUtil: MetricsUtil) { |
| 10 | + this.metricsUtil = metricsUtil; |
| 11 | + } |
| 12 | + |
| 13 | + provideCodeLenses(document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> { |
| 14 | + if (!this.metricsUtil.appConfig.codeMetricsDisplayed) return; |
| 15 | + if (!this.metricsUtil.appConfig.codeMetricsSettings.CodeLensEnabled) return; |
| 16 | + return this.metricsUtil.getMetrics(document).then(metrics => { |
| 17 | + const result: CodeLens[] = metrics.map( |
| 18 | + model => new CodeMetricsCodeLens(model, this.metricsUtil.toRange(model, document)) |
| 19 | + ); |
| 20 | + return result; |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + resolveCodeLens(codeLens: CodeLens, token: CancellationToken): CodeLens { |
| 25 | + if (codeLens instanceof CodeMetricsCodeLens) { |
| 26 | + codeLens.command = { |
| 27 | + title: this.metricsUtil.format(codeLens), |
| 28 | + command: "codemetrics.showCodeMetricsCodeLensInfo", |
| 29 | + arguments: [codeLens] |
| 30 | + }; |
| 31 | + return codeLens; |
| 32 | + } |
| 33 | + return null; |
| 34 | + } |
| 35 | +} |
0 commit comments