microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/settingsHelper.ts
96lines · modeblame
3d1881c7Joshua Skelton10 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
| 4 | import * as vscode from "vscode"; | |
| 5 | import path = require("path"); | |
df4bce40digeff10 years ago | 6 | import {ConfigurationReader} from "../common/configurationReader"; |
| 7 | import {Packager} from "../common/packager"; | |
5bc682d4Alexander Sorokin9 years ago | 8 | import {LogLevel} from "../common/log/logHelper"; |
3d1881c7Joshua Skelton10 years ago | 9 | |
| 10 | export class SettingsHelper { | |
| 11 | | |
9e81e40fPatricio Beltran10 years ago | 12 | /** |
| 13 | * Path to the workspace settings file | |
| 14 | */ | |
3d1881c7Joshua Skelton10 years ago | 15 | public static get settingsJsonPath(): string { |
| 16 | return path.join(vscode.workspace.rootPath, ".vscode", "settings.json"); | |
| 17 | } | |
| 18 | | |
| 19 | /** | |
9e81e40fPatricio Beltran10 years ago | 20 | * Enable javascript intellisense via typescript. |
3d1881c7Joshua Skelton10 years ago | 21 | */ |
9e81e40fPatricio Beltran10 years ago | 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.`); | |
3d1881c7Joshua Skelton10 years ago | 24 | } |
| 25 | | |
| 26 | /** | |
9e81e40fPatricio Beltran10 years ago | 27 | * Removes javascript intellisense via typescript. |
3d1881c7Joshua Skelton10 years ago | 28 | */ |
9e81e40fPatricio Beltran10 years ago | 29 | public static notifyUserToRemoveTSDKFromSettingsJson(path: string): void { |
| 30 | vscode.window.showInformationMessage(`Please remove \"typescript.tsdk\": \"${path}\" from .vscode/settings.json and restart VSCode afterwards.`); | |
3d1881c7Joshua Skelton10 years ago | 31 | } |
| 32 | | |
| 33 | /** | |
9e81e40fPatricio Beltran10 years ago | 34 | * Get the path of the Typescript TSDK as it is in the workspace configuration |
3d1881c7Joshua Skelton10 years ago | 35 | */ |
9e81e40fPatricio Beltran10 years ago | 36 | public static getTypeScriptTsdk(): string { |
| 37 | const workspaceConfiguration = vscode.workspace.getConfiguration(); | |
| 38 | if (workspaceConfiguration.has("typescript.tsdk")) { | |
1b4090cePatricio Beltran10 years ago | 39 | const tsdk = workspaceConfiguration.get("typescript.tsdk"); |
| 40 | if (tsdk) { | |
| 41 | return ConfigurationReader.readString(tsdk); | |
| 42 | } | |
9e81e40fPatricio Beltran10 years ago | 43 | } |
| 44 | return null; | |
3d1881c7Joshua Skelton10 years ago | 45 | } |
bed90dbdJoshua Skelton10 years ago | 46 | |
8a9925eeEric Hamilton10 years ago | 47 | /** |
9e81e40fPatricio Beltran10 years ago | 48 | * We get the packager port configured by the user |
8a9925eeEric Hamilton10 years ago | 49 | */ |
df4bce40digeff10 years ago | 50 | public static getPackagerPort(): number { |
9e81e40fPatricio Beltran10 years ago | 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; | |
df4bce40digeff10 years ago | 56 | } |
5bc682d4Alexander Sorokin9 years ago | 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 | } | |
38edb09eAlexander Sorokin9 years ago | 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 | } | |
3d1881c7Joshua Skelton10 years ago | 96 | } |