Skip to content

Commit 59f8435

Browse files
committed
not using settings for environments any more
1 parent c638cff commit 59f8435

File tree

17 files changed

+118
-72
lines changed

17 files changed

+118
-72
lines changed

src/extension.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { EditorHelper } from './services/EditorHelper';
1515
import { CodeInspector } from './services/codeInspector';
1616
import { VsCodeDebugInstrumentation } from './instrumentation/vscodeInstrumentation';
1717
import { GoLanguageExtractor } from './services/languages/go/languageExtractor';
18+
import { WorkspaceState } from './state';
1819

1920
export async function activate(context: vscode.ExtensionContext)
2021
{
@@ -26,17 +27,19 @@ export async function activate(context: vscode.ExtensionContext)
2627
const supportedSourceControls = [
2728
new Git()
2829
];
30+
31+
const workspaceState = new WorkspaceState(context.workspaceState);
2932
const sourceControl = new SourceControl(supportedSourceControls);
3033
const codeInspector = new CodeInspector();
3134
const symbolProvider = new SymbolProvider(supportedLanguages, codeInspector);
32-
const analyticsProvider = new AnalyticsProvider();
33-
const documentInfoProvider = new DocumentInfoProvider(analyticsProvider, symbolProvider);
35+
const analyticsProvider = new AnalyticsProvider(workspaceState);
36+
const documentInfoProvider = new DocumentInfoProvider(analyticsProvider, symbolProvider,workspaceState);
3437
const editorHelper = new EditorHelper(sourceControl, documentInfoProvider);
3538

36-
if(!Settings.environment.value){
39+
if(!workspaceState.environment){
3740
const firstEnv = (await analyticsProvider.getEnvironments()).firstOrDefault();
3841
if(firstEnv) {
39-
await Settings.environment.set(firstEnv);
42+
workspaceState.setEnvironment(firstEnv);
4043
}
4144
}
4245
context.subscriptions.push(new AnaliticsCodeLens(documentInfoProvider));
@@ -45,7 +48,7 @@ export async function activate(context: vscode.ExtensionContext)
4548
context.subscriptions.push(sourceControl);
4649
context.subscriptions.push(documentInfoProvider);
4750
context.subscriptions.push(new CodeAnalyticsView(analyticsProvider, documentInfoProvider,
48-
context.extensionUri, editorHelper));
51+
context.extensionUri, editorHelper,workspaceState));
4952
context.subscriptions.push(new ErrorsLineDecorator(documentInfoProvider));
5053
context.subscriptions.push(new HotspotMarkerDecorator(documentInfoProvider));
5154
context.subscriptions.push(new VsCodeDebugInstrumentation(analyticsProvider));

src/services/analyticsProvider.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { decimal, integer } from "vscode-languageclient";
99
import * as os from 'os';
1010
import { stringify } from "querystring";
1111
import { SpanInfo } from "../views/codeAnalytics/InsightListView/CommonInsightObjects";
12+
import { WorkspaceState } from "../state";
1213

1314

1415
export enum Impact
@@ -324,6 +325,9 @@ export interface CodeObjectErrorDetails extends CodeObjectErrorResponse{
324325

325326
export class AnalyticsProvider
326327
{
328+
public constructor(private state: WorkspaceState){
329+
330+
}
327331
public async getEnvironments() : Promise<string[]>
328332
{
329333
try
@@ -351,7 +355,7 @@ export class AnalyticsProvider
351355

352356
public async getCodeObjectsErrors(codeObjectIds: string []): Promise<CodeObjectErrorResponse[]>
353357
{
354-
let params : [string, any][] = [["environment",Settings.environment.value]];
358+
let params : [string, any][] = [["environment",this.state.environment]];
355359
codeObjectIds.forEach(o=> params.push(["codeObjectId",o]));
356360

357361
const response = await this.send<CodeObjectErrorResponse[]>(
@@ -421,7 +425,7 @@ export class AnalyticsProvider
421425
`/CodeAnalytics/insights`,
422426
undefined,
423427
{
424-
environment: Settings.environment.value
428+
environment: this.state.environment
425429
});
426430
return response;
427431
}
@@ -435,7 +439,7 @@ export class AnalyticsProvider
435439
undefined,
436440
{
437441
codeObjectIds: codeObjectIds,
438-
environment: Settings.environment.value
442+
environment: this.state.environment
439443
});
440444
return response;
441445
}
@@ -448,7 +452,7 @@ export class AnalyticsProvider
448452
'POST',
449453
`/CodeAnalytics/summary`,
450454
undefined,
451-
{codeObjectIds: symbolsIdentifiers, environment: Settings.environment.value});
455+
{codeObjectIds: symbolsIdentifiers, environment: this.state.environment});
452456

453457
return response;
454458
}
@@ -462,7 +466,7 @@ export class AnalyticsProvider
462466
{
463467
try
464468
{
465-
let params : [string, any][] = [["environment",Settings.environment.value]];
469+
let params : [string, any][] = [["environment",this.state.environment]];
466470

467471
if(sort){
468472
params.push(["sort",sort]);
@@ -494,7 +498,7 @@ export class AnalyticsProvider
494498
'POST',
495499
`/CodeAnalytics/errorFlow`,
496500
undefined,
497-
{id: errorFlowId, environment: Settings.environment.value});
501+
{id: errorFlowId, environment: this.state.environment});
498502

499503
return response;
500504
}

src/services/documentInfoProvider.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { EndpointInfo, SpanLocationInfo as SpanLocationInfo, SymbolInfo, CodeObj
99
import { InstrumentationInfo } from './EditorHelper';
1010
import { SymbolInformation } from 'vscode';
1111
import { Settings } from '../settings';
12+
import { WorkspaceState } from '../state';
1213

1314
export class DocumentInfoProvider implements vscode.Disposable
1415
{
@@ -17,27 +18,28 @@ export class DocumentInfoProvider implements vscode.Disposable
1718
private _timer;
1819

1920
private ensureDocDictionaryForEnv(){
20-
let envDictionary = this._documentsByEnv[Settings.environment.value];
21+
let envDictionary = this._documentsByEnv[this.workspaceState.environment];
2122
if (!envDictionary){
22-
this._documentsByEnv[Settings.environment.value]={};
23+
this._documentsByEnv[this.workspaceState.environment]={};
2324
}
2425
}
2526
get _documents(): Dictionary<string, DocumentInfoContainer> {
2627

2728
this.ensureDocDictionaryForEnv();
28-
return this._documentsByEnv[Settings.environment.value];
29+
return this._documentsByEnv[this.workspaceState.environment];
2930
}
3031

3132
set _documents(value: Dictionary<string, DocumentInfoContainer>){
3233
this.ensureDocDictionaryForEnv();
33-
this._documentsByEnv[Settings.environment.value]=value;
34+
this._documentsByEnv[this.workspaceState.environment]=value;
3435

3536
}
3637

3738

3839
constructor(
3940
public analyticsProvider: AnalyticsProvider,
40-
public symbolProvider: SymbolProvider)
41+
public symbolProvider: SymbolProvider,
42+
private workspaceState: WorkspaceState)
4143
{
4244
this._disposables.push(vscode.workspace.onDidCloseTextDocument((doc: vscode.TextDocument) => this.removeDocumentInfo(doc)));
4345

src/settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ export class SettingsKey<T>
3131
}
3232
}
3333

34+
3435
export class Settings
3536
{
3637
public static readonly url = new SettingsKey('url', '');
3738

3839
public static readonly enableCodeLens = new SettingsKey('enableCodeLens', true);
3940

40-
public static readonly environment = new SettingsKey('environment', '');
41+
// public static readonly environment = new SettingsKey('environment', '');
4142

4243
public static readonly jaegerAddress = new SettingsKey('jaegerAddress', '');
4344

src/state.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as vscode from 'vscode';
2+
3+
export class WorkspaceState {
4+
5+
environmentKey:string = "environment";
6+
7+
public constructor(private state: vscode.Memento){
8+
9+
}
10+
11+
public get environment():string {
12+
const result:string|undefined = this.state.get(this.environmentKey);
13+
if (result != null){
14+
return result;
15+
}
16+
else{
17+
return "";
18+
}
19+
}
20+
21+
public async setEnvironment(environmet: string) {
22+
await this.state.update(this.environmentKey, environmet);
23+
}
24+
}

src/views/ListView/EmptyGroupItemTemplate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Settings } from "../../settings";
2+
import { WorkspaceState } from "../../state";
23
import { WebViewUris } from "../webViewUtils";
34
import { IListViewItemBase } from "./IListViewItem"
45

56
export class EmptyGroupItemTemplate implements IListViewItemBase {
67

7-
public constructor( private viewUris: WebViewUris){
8+
public constructor( private viewUris: WebViewUris,
9+
private _workspaceState: WorkspaceState){
810

911
}
1012

@@ -13,7 +15,7 @@ export class EmptyGroupItemTemplate implements IListViewItemBase {
1315
return `<div class="list-item">
1416
<div class="list-item-content-area">
1517
<div class="list-item-header"><strong>No data received</strong></div>
16-
<div class="list-item-content-description">No data received yet about this code object from the selected environment: ${Settings.environment.value}</div>
18+
<div class="list-item-content-description">No data received yet about this code object from the selected environment: ${this._workspaceState.environment}</div>
1719
</div>
1820
<div class="list-item-right-area">
1921
<img class="insight-main-image" style="align-self:center;" src="${this.viewUris.image("no-data.png")}" width="32" height="32">

src/views/codeAnalytics/AdminInsights/noCodeObjectMessage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AnalyticsProvider } from "../../../services/analyticsProvider";
22
import { DocumentInfo } from "../../../services/documentInfoProvider";
3+
import { WorkspaceState } from "../../../state";
34
import { WebViewUris } from "../../webViewUtils";
45
import { CodeObjectGroupEnvironments } from "../CodeObjectGroups/CodeObjectGroupEnvUsage";
56
import { HtmlHelper } from "../common";
@@ -8,7 +9,8 @@ import { OverlayView } from "../overlayView";
89
export class NoCodeObjectMessage{
910

1011
constructor(private _analyticsProvider: AnalyticsProvider,
11-
private _viewUris: WebViewUris){
12+
private _viewUris: WebViewUris,
13+
private _workspaceState: WorkspaceState){
1214

1315
}
1416
public async showCodeSelectionNotFoundMessage(docInfo: DocumentInfo){
@@ -27,7 +29,7 @@ export class NoCodeObjectMessage{
2729
}
2830

2931
}
30-
let html=new CodeObjectGroupEnvironments(this._viewUris).getUsageHtml(undefined,undefined,usageStatuses);;
32+
let html=new CodeObjectGroupEnvironments(this._viewUris, this._workspaceState).getUsageHtml(undefined,undefined,usageStatuses);;
3133
if (links.length>0){
3234
html += /*html*/ `
3335
${HtmlHelper.getInfoMessage("No function is currently selected. Please select one of the following functions to see their data:")}

src/views/codeAnalytics/CodeObjectGroups/CodeObjectGroupEnvUsage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Settings } from "../../../settings";
33
import { WebViewUris } from "../../webViewUtils";
44
import * as os from 'os';
55
import moment = require("moment");
6+
import { WorkspaceState } from "../../../state";
67

78
export interface IRenderCodeObjectGroupEnvironments{
89

@@ -12,12 +13,13 @@ export interface IRenderCodeObjectGroupEnvironments{
1213

1314
export class CodeObjectGroupEnvironments implements IRenderCodeObjectGroupEnvironments{
1415

15-
public constructor(private _viewUris: WebViewUris){
16+
public constructor(private _viewUris: WebViewUris,
17+
private _workspaceState: WorkspaceState){
1618

1719
}
1820

1921
private getSelectedOrUnselectedTag(environment: string){
20-
if (environment===Settings.environment.value){
22+
if (environment===this._workspaceState.environment){
2123
return "codeobj-environment-usage-label-selected";
2224
}else{
2325
return "codeobj-environment-usage-label";

src/views/codeAnalytics/Histogram/histogramPanel.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
import { stringify } from "querystring";
22
import { AnalyticsProvider, DurationRecord, PercentileDuration } from "../../../services/analyticsProvider";
33
import { Settings } from "../../../settings";
4+
import { WorkspaceState } from "../../../state";
45
import { SpanInfo } from "../InsightListView/CommonInsightObjects";
56

67
export class HistogramPanel {
78

89

910

10-
constructor(private _analyticsProvider: AnalyticsProvider){
11+
constructor(private _analyticsProvider: AnalyticsProvider,
12+
private _workspaceState: WorkspaceState){
1113

1214
}
13-
14-
private durationRecordToJS(durationRecord: DurationRecord):string{
15-
16-
let date='';
17-
const r=durationRecord.time;
18-
const d = new Date(r.toISOString());
19-
date+=`[new Date(]${r.year()}, ${r.month()}, ${d.getDate()}, ${r.hours()}, ${r.minutes()},${r.seconds()},${r.milliseconds()})`;
20-
let durations = (durationRecord.duration/1000000).toPrecision(2).toString();
21-
return `{x: ${date},y: ${durations}}`;
22-
2315

24-
}
2516

2617
private getXAxisData(durationRecords: DurationRecord[]):string{
2718
var dateStrings = durationRecords.map(x=>x.time).map(d=>{
@@ -92,7 +83,7 @@ export class HistogramPanel {
9283

9384

9485
const histogramData = await this._analyticsProvider.getSpanHistogramData(spanName, instrumentationLibrary,
95-
codeObjectId, Settings.environment.value);
86+
codeObjectId, this._workspaceState.environment);
9687

9788
let dataByPercentile = histogramData.percentileDurations.groupBy(x=>x.percentile);
9889
let percentiles = Object.keys(dataByPercentile);

src/views/codeAnalytics/InsightListView/ItemRender/SpanItemRendering.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class SpanItemHtmlRendering{
4747
public spanDurationItemHtml(insight: SpanDurationsInsight): string{
4848

4949
const percentileHtmls = [];
50-
const changeHtml = [];
5150
if (insight.percentiles.length===0){
5251
return this.getStillCalculatingHtml();
5352
}
@@ -105,12 +104,9 @@ export class SpanItemHtmlRendering{
105104
let traceHtml = ``;
106105
if (Settings.jaegerAddress.value){
107106

108-
109-
110107
const traceLabelsAtt = `data-trace-label="${traceLabels.join(",")}"`;
111108
const traceIdAtt = `data-trace-id="${traceIds.join(",")}"`;
112109

113-
114110
traceHtml=`
115111
<span style="padding-left: 10px;" class="trace-link link" data-jaeger-address="${Settings.jaegerAddress.value}" data-span-name="${insight.span}"
116112
${traceLabelsAtt} ${traceIdAtt} >

0 commit comments

Comments
 (0)