microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e45838cbf8bb84beab7d36042bcdbc57fe0319c8

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/settingsHelper.ts

96lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as vscode from "vscode";
5import path = require("path");
6import {ConfigurationReader} from "../common/configurationReader";
7import {Packager} from "../common/packager";
8import {LogLevel} from "../common/log/logHelper";
9
10export class SettingsHelper {
11
12 /**
13 * Path to the workspace settings file
14 */
15 public static get settingsJsonPath(): string {
16 return path.join(vscode.workspace.rootPath, ".vscode", "settings.json");
17 }
18
19 /**
20 * Enable javascript intellisense via typescript.
21 */
22 public static notifyUserToAddTSDKInSettingsJson(path: string): void {
23 vscode.window.showInformationMessage(`Please make sure you have \"typescript.tsdk\": \"${path}\" in .vscode/settings.json and restart VSCode afterwards.`);
24 }
25
26 /**
27 * Removes javascript intellisense via typescript.
28 */
29 public static notifyUserToRemoveTSDKFromSettingsJson(path: string): void {
30 vscode.window.showInformationMessage(`Please remove \"typescript.tsdk\": \"${path}\" from .vscode/settings.json and restart VSCode afterwards.`);
31 }
32
33 /**
34 * Get the path of the Typescript TSDK as it is in the workspace configuration
35 */
36 public static getTypeScriptTsdk(): string {
37 const workspaceConfiguration = vscode.workspace.getConfiguration();
38 if (workspaceConfiguration.has("typescript.tsdk")) {
39 const tsdk = workspaceConfiguration.get("typescript.tsdk");
40 if (tsdk) {
41 return ConfigurationReader.readString(tsdk);
42 }
43 }
44 return null;
45 }
46
47 /**
48 * We get the packager port configured by the user
49 */
50 public static getPackagerPort(): number {
51 const workspaceConfiguration = vscode.workspace.getConfiguration();
52 if (workspaceConfiguration.has("react-native.packager.port")) {
53 return ConfigurationReader.readInt(workspaceConfiguration.get("react-native.packager.port"));
54 }
55 return Packager.DEFAULT_PORT;
56 }
57
58 /**
59 * Get showInternalLogs setting
60 */
61 public static getShowInternalLogs(): boolean {
62 const workspaceConfiguration = vscode.workspace.getConfiguration();
63 if (workspaceConfiguration.has("react-native-tools.showInternalLogs")) {
64 return ConfigurationReader.readBoolean(workspaceConfiguration.get("react-native-tools.showInternalLogs"));
65 }
66 return false;
67 }
68
69 /**
70 * Get logLevel setting
71 */
72 public static getLogLevel(): LogLevel {
73 const workspaceConfiguration = vscode.workspace.getConfiguration();
74 if (workspaceConfiguration.has("react-native-tools.logLevel")) {
75 let logLevelString: string = ConfigurationReader.readString(workspaceConfiguration.get("react-native-tools.logLevel"));
76 return <LogLevel>parseInt(LogLevel[<any>logLevelString], 10);
77 }
78 return LogLevel.None;
79 }
80
81 /**
82 * Get the React Native project root path
83 */
84 public static getReactNativeProjectRoot(): string {
85 const workspaceConfiguration = vscode.workspace.getConfiguration();
86 if (workspaceConfiguration.has("react-native-tools.projectRoot")) {
87 let projectRoot: string = ConfigurationReader.readString(workspaceConfiguration.get("react-native-tools.projectRoot"));
88 if (path.isAbsolute(projectRoot)) {
89 return projectRoot;
90 } else {
91 return path.resolve(vscode.workspace.rootPath, projectRoot);
92 }
93 }
94 return vscode.workspace.rootPath;
95 }
96}
97