Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: pkg/analysis_server/lib/src/server_options.dart

Issue 2765063002: Introducing `IdeOptions`. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/ide_options.dart ('k') | pkg/analysis_server/test/server_options_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/server_options.dart
diff --git a/pkg/analysis_server/lib/src/server_options.dart b/pkg/analysis_server/lib/src/server_options.dart
deleted file mode 100644
index 2eff6d9d4c403c38996ebdd879efb3dbd8492212..0000000000000000000000000000000000000000
--- a/pkg/analysis_server/lib/src/server_options.dart
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library analysis_server.src.server_options;
-
-import 'dart:collection';
-import 'dart:io';
-
-import 'package:path/path.dart' as path;
-import 'package:yaml/yaml.dart';
-
-//TODO: consider renaming (https://github.com/dart-lang/sdk/issues/23927)
-const _optionsFileName = '.dart_analysis_server.yaml';
-
-/// The shared options instance.
-ServerOptions _serverOptions;
-
-/// Server options.
-ServerOptions get serverOptions {
- if (_serverOptions == null) {
- _serverOptions = _loadOptions();
- }
- return _serverOptions;
-}
-
-/// Find the options file relative to the user's home directory.
-/// Returns `null` if there is none or the user's homedir cannot
-/// be derived from the platform's environment (e.g., `HOME` and
-/// `UserProfile` for mac/Linux and Windows respectively).
-File _findOptionsFile() {
- String home;
- Map<String, String> envVars = Platform.environment;
- if (Platform.isMacOS || Platform.isLinux) {
- home = envVars['HOME'];
- } else if (Platform.isWindows) {
- home = envVars['UserProfile'];
- }
-
- if (home == null) {
- return null;
- }
-
- return new File(path.context.join(home, _optionsFileName));
-}
-
-ServerOptions _loadOptions() {
- File optionsFile = _findOptionsFile();
- try {
- if (optionsFile != null && optionsFile.existsSync()) {
- return new ServerOptions.fromFile(optionsFile);
- }
- } catch (e) {
- // Fall through.
- }
- return new ServerOptions._empty();
-}
-
-/// Describes options captured in an external options file.
-/// `ServerOptions` are described in a file `dart_analysis_server.options`
-/// located in the user's home directory. Options are defined in YAML and
-/// read once and cached. In order for changes to be picked up, server needs
-/// to be restarted.
-class ServerOptions {
- final Map<String, dynamic> _options = new HashMap<String, dynamic>();
-
- /// Load options from the given [contents].
- ServerOptions.fromContents(String contents) {
- _readOptions(contents);
- }
-
- /// Load options from the given [options] file.
- factory ServerOptions.fromFile(File options) =>
- new ServerOptions.fromContents(options.readAsStringSync());
-
- /// Create an empty options object.
- ServerOptions._empty();
-
- /// Get the value for `key` from the options file.
- dynamic operator [](String key) => _options[key];
-
- /// Get a String value for this `key` or [defaultValue] if undefined
- /// or not a String.
- String getStringValue(String key, {String defaultValue: null}) {
- var value = _options[key];
- if (value is String) {
- return value;
- }
- return defaultValue;
- }
-
- /// Test whether the given [booleanPropertyKey] is set to the value `true`,
- /// falling back to [defaultValue] if undefined.
- /// For example:
- /// myDebugOption1:true
- /// myDebugOption2:TRUE # Also true (case and trailing whitespace are ignored).
- /// myDebugOption3:false
- /// myDebugOption4:off # Treated as `false`.
- /// myDebugOption5:on # Also read as `false`.
- bool isSet(String booleanPropertyKey, {bool defaultValue: false}) {
- var value = _options[booleanPropertyKey];
- if (value == null) {
- return defaultValue;
- }
- return value == true;
- }
-
- void _readOptions(String contents) {
- var doc = loadYaml(contents);
- if (doc is YamlMap) {
- doc.forEach((k, v) {
- if (k is String) {
- _options[k] = v;
- }
- });
- }
- }
-}
« no previous file with comments | « pkg/analysis_server/lib/src/ide_options.dart ('k') | pkg/analysis_server/test/server_options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698