Skip to content

Commit 1c327ff

Browse files
committed
Refactor services. Make tnsPath an optional workspace setting instead of configuration in lauch.json
1 parent 794f3e4 commit 1c327ff

21 files changed

+191
-157
lines changed

package.json

+5-10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
"type": "boolean",
6969
"default": true,
7070
"description": "Enables the extension tracking."
71+
},
72+
"nativescript.tnsPath": {
73+
"type": "string",
74+
"default": "tns",
75+
"description": "Path to the NativeScript CLI executable."
7176
}
7277
}
7378
},
@@ -215,11 +220,6 @@
215220
"type": "boolean",
216221
"description": "Whether to sync files from node_modules folder.",
217222
"default": false
218-
},
219-
"nativescriptCliPath": {
220-
"type": "string",
221-
"description": "Path to the nativescript CLI to be used by the NativeScript extension.",
222-
"default": "tns"
223223
}
224224
}
225225
},
@@ -258,11 +258,6 @@
258258
"type": "string",
259259
"description": "NativeScript platform",
260260
"default": null
261-
},
262-
"nativescriptCliPath": {
263-
"type": "string",
264-
"description": "Path to the nativescript CLI to be used by the NativeScript extension.",
265-
"default": "tns"
266261
}
267262
}
268263
}

src/analytics/AnalyticsService.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as os from 'os';
2-
import * as vscode from 'vscode';
32
import { Version } from '../common/version';
43
import { GUAService } from './GUAService';
54
import { TelerikAnalyticsService } from './TelerikAnalyticsService';
65
import { AnalyticsBaseInfo, OperatingSystem } from './AnalyticsBaseInfo';
7-
import { ExtensionHostServices as Services } from '../services/extensionHostServices';
6+
import { Services } from '../services/extensionHostServices';
87
import * as utils from '../common/utilities';
98

109
export class AnalyticsService {
@@ -29,7 +28,7 @@ export class AnalyticsService {
2928
}
3029

3130
constructor() {
32-
this._analyticsEnabled = vscode.workspace.getConfiguration('nativescript').get('analytics.enabled') as boolean;
31+
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
3332
let operatingSystem = OperatingSystem.Other;
3433
switch(process.platform) {
3534
case 'win32': { operatingSystem = OperatingSystem.Windows; break; }
@@ -39,7 +38,7 @@ export class AnalyticsService {
3938
};
4039

4140
this._baseInfo = {
42-
cliVersion: Services.cli.version.toString(),
41+
cliVersion: Services.cli().version.toString(),
4342
extensionVersion: utils.getInstalledExtensionVersion().toString(),
4443
operatingSystem: operatingSystem,
4544
userId: AnalyticsService.generateMachineId()

src/common/workspaceConfigService.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as vscode from 'vscode';
2+
3+
export class WorkspaceConfigService {
4+
public get isAnalyticsEnabled(): boolean {
5+
return vscode.workspace.getConfiguration('nativescript').get('analytics.enabled') as boolean;
6+
}
7+
8+
public get tnsPath(): string {
9+
return vscode.workspace.getConfiguration('nativescript').get('tnsPath') as string;
10+
}
11+
}

src/custom-typings/debugProtocolExtensions.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ declare module 'vscode-debugprotocol' {
1515
diagnosticLogging?: boolean;
1616
tnsArgs?: string[];
1717
tnsOutput?: string;
18-
nativescriptCliPath?: string;
1918
}
2019

2120
interface ILaunchRequestArgs extends DebugProtocol.LaunchRequestArguments, IRequestArgs {

src/debug-adapter/adapter/adapterProxy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*--------------------------------------------------------*/
44

55
import * as utils from '../../common/utilities';
6-
import {DebugAdapterServices as Services} from '../../services/debugAdapterServices';
6+
import {Services} from '../../services/debugAdapterServices';
77
import {DebugProtocol} from 'vscode-debugprotocol';
88

99
export type EventHandler = (event: DebugProtocol.Event) => void;
@@ -78,7 +78,7 @@ export class AdapterProxy {
7878
this._eventHandler(event);
7979
}
8080
} catch (e) {
81-
Services.logger.error('Error handling adapter event: ' + (e ? e.stack : ''));
81+
Services.logger().error('Error handling adapter event: ' + (e ? e.stack : ''));
8282
}
8383
}
8484
}

src/debug-adapter/adapter/pathTransformer.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*--------------------------------------------------------*/
44

55
import * as utils from '../../common/utilities';
6-
import {DebugAdapterServices as Services} from '../../services/debugAdapterServices';
6+
import {Services} from '../../services/debugAdapterServices';
77
import {DebugProtocol} from 'vscode-debugprotocol';
88

99
interface IPendingBreakpoint {
@@ -43,15 +43,15 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
4343

4444
if (utils.isURL(args.source.path)) {
4545
// already a url, use as-is
46-
Services.logger.log(`Paths.setBP: ${args.source.path} is already a URL`);
46+
Services.logger().log(`Paths.setBP: ${args.source.path} is already a URL`);
4747
resolve();
4848
return;
4949
}
5050

5151
const url = utils.canonicalizeUrl(args.source.path);
5252
if (this._clientPathToWebkitUrl.has(url)) {
5353
args.source.path = this._clientPathToWebkitUrl.get(url);
54-
Services.logger.log(`Paths.setBP: Resolved ${url} to ${args.source.path}`);
54+
Services.logger().log(`Paths.setBP: Resolved ${url} to ${args.source.path}`);
5555
resolve();
5656
}
5757
else if (this.inferedDeviceRoot) {
@@ -71,11 +71,11 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
7171
inferedUrl = inferedUrl.replace(`.${this._platform}.`, '.');
7272

7373
args.source.path = inferedUrl;
74-
Services.logger.log(`Paths.setBP: Resolved (by infering) ${url} to ${args.source.path}`);
74+
Services.logger().log(`Paths.setBP: Resolved (by infering) ${url} to ${args.source.path}`);
7575
resolve();
7676
}
7777
else {
78-
Services.logger.log(`Paths.setBP: No target url cached for client path: ${url}, waiting for target script to be loaded.`);
78+
Services.logger().log(`Paths.setBP: No target url cached for client path: ${url}, waiting for target script to be loaded.`);
7979
args.source.path = url;
8080
this._pendingBreakpointsByPath.set(args.source.path, { resolve, reject, args });
8181
}
@@ -96,7 +96,7 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
9696
if (!this.inferedDeviceRoot && this._platform === "android")
9797
{
9898
this.inferedDeviceRoot = utils.inferDeviceRoot(this._appRoot, this._platform, webkitUrl);
99-
Services.logger.log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n");
99+
Services.logger().log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n");
100100

101101
if (this.inferedDeviceRoot.indexOf("/data/user/0/") != -1)
102102
{
@@ -107,17 +107,17 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
107107
const clientPath = utils.webkitUrlToClientPath(this._appRoot, this._platform, webkitUrl);
108108

109109
if (!clientPath) {
110-
Services.logger.log(`Paths.scriptParsed: could not resolve ${webkitUrl} to a file in the workspace. webRoot: ${this._appRoot}`);
110+
Services.logger().log(`Paths.scriptParsed: could not resolve ${webkitUrl} to a file in the workspace. webRoot: ${this._appRoot}`);
111111
} else {
112-
Services.logger.log(`Paths.scriptParsed: resolved ${webkitUrl} to ${clientPath}. webRoot: ${this._appRoot}`);
112+
Services.logger().log(`Paths.scriptParsed: resolved ${webkitUrl} to ${clientPath}. webRoot: ${this._appRoot}`);
113113
this._clientPathToWebkitUrl.set(clientPath, webkitUrl);
114114
this._webkitUrlToClientPath.set(webkitUrl, clientPath);
115115

116116
event.body.scriptUrl = clientPath;
117117
}
118118

119119
if (this._pendingBreakpointsByPath.has(event.body.scriptUrl)) {
120-
Services.logger.log(`Paths.scriptParsed: Resolving pending breakpoints for ${event.body.scriptUrl}`);
120+
Services.logger().log(`Paths.scriptParsed: Resolving pending breakpoints for ${event.body.scriptUrl}`);
121121
const pendingBreakpoint = this._pendingBreakpointsByPath.get(event.body.scriptUrl);
122122
this._pendingBreakpointsByPath.delete(event.body.scriptUrl);
123123
this.setBreakpoints(pendingBreakpoint.args).then(pendingBreakpoint.resolve, pendingBreakpoint.reject);

src/debug-adapter/adapter/sourceMaps/pathUtilities.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import * as Path from 'path';
88
import * as URL from 'url';
9-
import {DebugAdapterServices as Services} from '../../../services/debugAdapterServices';
9+
import {Services} from '../../../services/debugAdapterServices';
1010
import * as utils from '../../../common/utilities';
1111

1212
export function getPathRoot(p: string) {
@@ -83,16 +83,16 @@ export function getAbsSourceRoot(sourceRoot: string, webRoot: string, generatedP
8383
}
8484
}
8585

86-
Services.logger.log(`SourceMap: resolved sourceRoot ${sourceRoot} -> ${absSourceRoot}`);
86+
Services.logger().log(`SourceMap: resolved sourceRoot ${sourceRoot} -> ${absSourceRoot}`);
8787
} else {
8888
if (Path.isAbsolute(generatedPath)) {
8989
absSourceRoot = Path.dirname(generatedPath);
90-
Services.logger.log(`SourceMap: no sourceRoot specified, using script dirname: ${absSourceRoot}`);
90+
Services.logger().log(`SourceMap: no sourceRoot specified, using script dirname: ${absSourceRoot}`);
9191
} else {
9292
// runtime script is not on disk, resolve the sourceRoot location on disk
9393
const scriptPathDirname = Path.dirname(URL.parse(generatedPath).pathname);
9494
absSourceRoot = Path.join(webRoot, scriptPathDirname);
95-
Services.logger.log(`SourceMap: no sourceRoot specified, using webRoot + script path dirname: ${absSourceRoot}`);
95+
Services.logger().log(`SourceMap: no sourceRoot specified, using webRoot + script path dirname: ${absSourceRoot}`);
9696
}
9797
}
9898

src/debug-adapter/adapter/sourceMaps/sourceMapTransformer.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as path from 'path';
66
import * as fs from 'fs';
7-
import {DebugAdapterServices as Services} from '../../../services/debugAdapterServices';
7+
import {Services} from '../../../services/debugAdapterServices';
88
import {DebugProtocol} from 'vscode-debugprotocol';
99
import {ISourceMaps, SourceMaps} from './sourceMaps';
1010
import * as utils from '../../../common/utilities';
@@ -60,7 +60,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
6060
const argsPath = args.source.path;
6161
const mappedPath = this._sourceMaps.MapPathFromSource(argsPath);
6262
if (mappedPath) {
63-
Services.logger.log(`SourceMaps.setBP: Mapped ${argsPath} to ${mappedPath}`);
63+
Services.logger().log(`SourceMaps.setBP: Mapped ${argsPath} to ${mappedPath}`);
6464
args.authoredPath = argsPath;
6565
args.source.path = mappedPath;
6666

@@ -69,11 +69,11 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
6969
const mappedLines = args.lines.map((line, i) => {
7070
const mapped = this._sourceMaps.MapFromSource(argsPath, line, /*column=*/0);
7171
if (mapped) {
72-
Services.logger.log(`SourceMaps.setBP: Mapped ${argsPath}:${line}:0 to ${mappedPath}:${mapped.line}:${mapped.column}`);
72+
Services.logger().log(`SourceMaps.setBP: Mapped ${argsPath}:${line}:0 to ${mappedPath}:${mapped.line}:${mapped.column}`);
7373
mappedCols[i] = mapped.column;
7474
return mapped.line;
7575
} else {
76-
Services.logger.log(`SourceMaps.setBP: Mapped ${argsPath} but not line ${line}, column 0`);
76+
Services.logger().log(`SourceMaps.setBP: Mapped ${argsPath} but not line ${line}, column 0`);
7777
mappedCols[i] = 0;
7878
return line;
7979
}
@@ -101,10 +101,10 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
101101
});
102102
} else if (this._allRuntimeScriptPaths.has(argsPath)) {
103103
// It's a generated file which is loaded
104-
Services.logger.log(`SourceMaps.setBP: SourceMaps are enabled but ${argsPath} is a runtime script`);
104+
Services.logger().log(`SourceMaps.setBP: SourceMaps are enabled but ${argsPath} is a runtime script`);
105105
} else {
106106
// Source (or generated) file which is not loaded, need to wait
107-
Services.logger.log(`SourceMaps.setBP: ${argsPath} can't be resolved to a loaded script.`);
107+
Services.logger().log(`SourceMaps.setBP: ${argsPath} can't be resolved to a loaded script.`);
108108
this._pendingBreakpointsByPath.set(argsPath, { resolve, reject, args, requestSeq });
109109
return;
110110
}
@@ -132,10 +132,10 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
132132
response.breakpoints.forEach((bp, i) => {
133133
const mapped = this._sourceMaps.MapToSource(args.source.path, args.lines[i], args.cols[i]);
134134
if (mapped) {
135-
Services.logger.log(`SourceMaps.setBP: Mapped ${args.source.path}:${bp.line}:${bp.column} to ${mapped.path}:${mapped.line}`);
135+
Services.logger().log(`SourceMaps.setBP: Mapped ${args.source.path}:${bp.line}:${bp.column} to ${mapped.path}:${mapped.line}`);
136136
bp.line = mapped.line;
137137
} else {
138-
Services.logger.log(`SourceMaps.setBP: Can't map ${args.source.path}:${bp.line}:${bp.column}, keeping the line number as-is.`);
138+
Services.logger().log(`SourceMaps.setBP: Can't map ${args.source.path}:${bp.line}:${bp.column}, keeping the line number as-is.`);
139139
}
140140

141141
this._requestSeqToSetBreakpointsArgs.delete(requestSeq);
@@ -201,7 +201,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
201201
this._sourceMaps.ProcessNewSourceMap(event.body.scriptUrl, sourceMapUrlValue).then(() => {
202202
const sources = this._sourceMaps.AllMappedSources(event.body.scriptUrl);
203203
if (sources) {
204-
Services.logger.log(`SourceMaps.scriptParsed: ${event.body.scriptUrl} was just loaded and has mapped sources: ${JSON.stringify(sources)}`);
204+
Services.logger().log(`SourceMaps.scriptParsed: ${event.body.scriptUrl} was just loaded and has mapped sources: ${JSON.stringify(sources)}`);
205205
sources.forEach(this.resolvePendingBreakpoints, this);
206206
}
207207
});
@@ -241,7 +241,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
241241
private resolvePendingBreakpoints(sourcePath: string): void {
242242
// If there's a setBreakpoints request waiting on this script, go through setBreakpoints again
243243
if (this._pendingBreakpointsByPath.has(sourcePath)) {
244-
Services.logger.log(`SourceMaps.scriptParsed: Resolving pending breakpoints for ${sourcePath}`);
244+
Services.logger().log(`SourceMaps.scriptParsed: Resolving pending breakpoints for ${sourcePath}`);
245245
const pendingBreakpoint = this._pendingBreakpointsByPath.get(sourcePath);
246246
this._pendingBreakpointsByPath.delete(sourcePath);
247247

src/debug-adapter/adapter/sourceMaps/sourceMaps.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as FS from 'fs';
1010
import {SourceMapConsumer} from 'source-map';
1111
import * as PathUtils from './pathUtilities';
1212
import * as utils from '../../../common/utilities';
13-
import {DebugAdapterServices as Services} from '../../../services/debugAdapterServices';
13+
import {Services} from '../../../services/debugAdapterServices';
1414

1515

1616
export interface MappingResult {
@@ -191,7 +191,7 @@ export class SourceMaps implements ISourceMaps {
191191
const matches = SourceMaps.SOURCE_MAPPING_MATCHER.exec(line);
192192
if (matches && matches.length === 2) {
193193
const uri = matches[1].trim();
194-
Services.logger.log(`_findSourceMapUrlInFile: source map url at end of generated file '${generatedFilePath}''`);
194+
Services.logger().log(`_findSourceMapUrlInFile: source map url at end of generated file '${generatedFilePath}''`);
195195
return uri;
196196
}
197197
}
@@ -329,7 +329,7 @@ export class SourceMaps implements ISourceMaps {
329329
}
330330

331331
if (!FS.existsSync(generatedFilePath)) {
332-
Services.logger.log("findGeneratedToSourceMappingSync: can't find the sourceMapping for file: " + generatedFilePath);
332+
Services.logger().log("findGeneratedToSourceMappingSync: can't find the sourceMapping for file: " + generatedFilePath);
333333
return null;
334334
}
335335

@@ -379,7 +379,7 @@ export class SourceMaps implements ISourceMaps {
379379
}
380380
}
381381
catch (e) {
382-
Services.logger.log(`can't parse inlince sourcemap. exception while processing data url (${e.stack})`);
382+
Services.logger().log(`can't parse inlince sourcemap. exception while processing data url (${e.stack})`);
383383
}
384384
}
385385

@@ -390,14 +390,14 @@ export class SourceMaps implements ISourceMaps {
390390
let contentsP: Promise<string>;
391391
if (utils.isURL(mapPath)) {
392392
contentsP = utils.getURL(mapPath).catch(e => {
393-
Services.logger.log(`SourceMaps.createSourceMap: Could not download map from ${mapPath}`);
393+
Services.logger().log(`SourceMaps.createSourceMap: Could not download map from ${mapPath}`);
394394
return null;
395395
});
396396
} else {
397397
contentsP = new Promise((resolve, reject) => {
398398
FS.readFile(mapPath, (err, data) => {
399399
if (err) {
400-
Services.logger.log(`SourceMaps.createSourceMap: Could not read map from ${mapPath}`);
400+
Services.logger().log(`SourceMaps.createSourceMap: Could not read map from ${mapPath}`);
401401
resolve(null);
402402
} else {
403403
resolve(data);
@@ -412,7 +412,7 @@ export class SourceMaps implements ISourceMaps {
412412
// Throws for invalid contents JSON
413413
return new SourceMap(pathToGenerated, contents, this._webRoot);
414414
} catch (e) {
415-
Services.logger.log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
415+
Services.logger().log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
416416
return null;
417417
}
418418
} else {
@@ -427,7 +427,7 @@ export class SourceMaps implements ISourceMaps {
427427
// Throws for invalid contents JSON
428428
return new SourceMap(pathToGenerated, contents, this._webRoot);
429429
} catch (e) {
430-
Services.logger.log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
430+
Services.logger().log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
431431
return null;
432432
}
433433
}
@@ -452,7 +452,7 @@ class SourceMap {
452452
* webRoot - an absolute path
453453
*/
454454
public constructor(generatedPath: string, json: string, webRoot: string) {
455-
Services.logger.log(`SourceMap: creating SM for ${generatedPath}`)
455+
Services.logger().log(`SourceMap: creating SM for ${generatedPath}`)
456456
this._generatedPath = generatedPath;
457457
this._webRoot = webRoot;
458458

0 commit comments

Comments
 (0)