microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.3.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/settingsHelper.ts

96lines · modeblame

3d1881c7Joshua Skelton10 years ago1// 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");
df4bce40digeff10 years ago6import {ConfigurationReader} from "../common/configurationReader";
7import {Packager} from "../common/packager";
5bc682d4Alexander Sorokin9 years ago8import {LogLevel} from "../common/log/logHelper";
3d1881c7Joshua Skelton10 years ago9
10export class SettingsHelper {
11
9e81e40fPatricio Beltran10 years ago12/**
13* Path to the workspace settings file
14*/
3d1881c7Joshua Skelton10 years ago15public static get settingsJsonPath(): string {
16return path.join(vscode.workspace.rootPath, ".vscode", "settings.json");
17}
18
19/**
9e81e40fPatricio Beltran10 years ago20* Enable javascript intellisense via typescript.
3d1881c7Joshua Skelton10 years ago21*/
9e81e40fPatricio Beltran10 years ago22public static notifyUserToAddTSDKInSettingsJson(path: string): void {
23vscode.window.showInformationMessage(`Please make sure you have \"typescript.tsdk\": \"${path}\" in .vscode/settings.json and restart VSCode afterwards.`);
3d1881c7Joshua Skelton10 years ago24}
25
26/**
9e81e40fPatricio Beltran10 years ago27* Removes javascript intellisense via typescript.
3d1881c7Joshua Skelton10 years ago28*/
9e81e40fPatricio Beltran10 years ago29public static notifyUserToRemoveTSDKFromSettingsJson(path: string): void {
30vscode.window.showInformationMessage(`Please remove \"typescript.tsdk\": \"${path}\" from .vscode/settings.json and restart VSCode afterwards.`);
3d1881c7Joshua Skelton10 years ago31}
32
33/**
9e81e40fPatricio Beltran10 years ago34* Get the path of the Typescript TSDK as it is in the workspace configuration
3d1881c7Joshua Skelton10 years ago35*/
9e81e40fPatricio Beltran10 years ago36public static getTypeScriptTsdk(): string {
37const workspaceConfiguration = vscode.workspace.getConfiguration();
38if (workspaceConfiguration.has("typescript.tsdk")) {
1b4090cePatricio Beltran10 years ago39const tsdk = workspaceConfiguration.get("typescript.tsdk");
40if (tsdk) {
41return ConfigurationReader.readString(tsdk);
42}
9e81e40fPatricio Beltran10 years ago43}
44return null;
3d1881c7Joshua Skelton10 years ago45}
bed90dbdJoshua Skelton10 years ago46
8a9925eeEric Hamilton10 years ago47/**
9e81e40fPatricio Beltran10 years ago48* We get the packager port configured by the user
8a9925eeEric Hamilton10 years ago49*/
df4bce40digeff10 years ago50public static getPackagerPort(): number {
9e81e40fPatricio Beltran10 years ago51const workspaceConfiguration = vscode.workspace.getConfiguration();
52if (workspaceConfiguration.has("react-native.packager.port")) {
53return ConfigurationReader.readInt(workspaceConfiguration.get("react-native.packager.port"));
54}
55return Packager.DEFAULT_PORT;
df4bce40digeff10 years ago56}
5bc682d4Alexander Sorokin9 years ago57
58/**
59* Get showInternalLogs setting
60*/
61public static getShowInternalLogs(): boolean {
62const workspaceConfiguration = vscode.workspace.getConfiguration();
63if (workspaceConfiguration.has("react-native-tools.showInternalLogs")) {
64return ConfigurationReader.readBoolean(workspaceConfiguration.get("react-native-tools.showInternalLogs"));
65}
66return false;
67}
68
69/**
70* Get logLevel setting
71*/
72public static getLogLevel(): LogLevel {
73const workspaceConfiguration = vscode.workspace.getConfiguration();
74if (workspaceConfiguration.has("react-native-tools.logLevel")) {
75let logLevelString: string = ConfigurationReader.readString(workspaceConfiguration.get("react-native-tools.logLevel"));
76return <LogLevel>parseInt(LogLevel[<any>logLevelString], 10);
77}
78return LogLevel.None;
79}
38edb09eAlexander Sorokin9 years ago80
81/**
82* Get the React Native project root path
83*/
84public static getReactNativeProjectRoot(): string {
85const workspaceConfiguration = vscode.workspace.getConfiguration();
86if (workspaceConfiguration.has("react-native-tools.projectRoot")) {
87let projectRoot: string = ConfigurationReader.readString(workspaceConfiguration.get("react-native-tools.projectRoot"));
88if (path.isAbsolute(projectRoot)) {
89return projectRoot;
90} else {
91return path.resolve(vscode.workspace.rootPath, projectRoot);
92}
93}
94return vscode.workspace.rootPath;
95}
3d1881c7Joshua Skelton10 years ago96}