Sort LSP files

No functional changes, this just sorts these files using edit.sortMembers to avoid having it mixed in with functional changes.

Change-Id: Ifb3a8cdf0ad20d4231d276aeb703b06a2da8aa2e
Reviewed-on: https://dart-review.googlesource.com/c/80443
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <dantup@google.com>
diff --git a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart
index 2298a78..3018259 100644
--- a/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart
+++ b/pkg/analysis_server/tool/lsp_spec/codegen_dart.dart
@@ -7,8 +7,8 @@
 import 'typescript.dart';
 
 final formatter = new DartFormatter();
-Map<String, TypeAlias> _typeAliases = {};
 Map<String, Interface> _interfaces = {};
+Map<String, TypeAlias> _typeAliases = {};
 
 String generateDartForTypes(List<ApiItem> types) {
   // Keep maps of items we may need to look up quickly later.
@@ -33,6 +33,28 @@
   return code;
 }
 
+/// Recursively gets all members from superclasses.
+List<Field> _getAllFields(Interface interface) {
+  // Handle missing interfaces (such as special cased interfaces that won't
+  // be included in this model).
+  if (interface == null) {
+    return [];
+  }
+  return interface.members
+      .whereType<Field>()
+      .followedBy(interface.baseTypes
+          .map((name) => _getAllFields(_interfaces[name]))
+          .expand((ts) => ts))
+      .toList();
+}
+
+/// Returns a copy of the list sorted by name.
+List<ApiItem> _getSorted(List<ApiItem> items) {
+  final sortedList = items.toList();
+  sortedList.sort((item1, item2) => item1.name.compareTo(item2.name));
+  return sortedList;
+}
+
 /// Maps reserved words and identifiers that cause issues in field names.
 String _makeValidIdentifier(String identifier) {
   // The SymbolKind class has uses these names which cause issues for code that
@@ -76,13 +98,6 @@
   return type;
 }
 
-/// Returns a copy of the list sorted by name.
-List<ApiItem> _getSorted(List<ApiItem> items) {
-  final sortedList = items.toList();
-  sortedList.sort((item1, item2) => item1.name.compareTo(item2.name));
-  return sortedList;
-}
-
 String _rewriteCommentReference(String comment) {
   final commentReferencePattern = new RegExp(r'\[([\w ]+)\]\(#(\w+)\)');
   return comment.replaceAllMapped(commentReferencePattern, (m) {
@@ -123,6 +138,17 @@
   buffer.writeIndentedln('static const ${cons.name} = ${cons.value};');
 }
 
+void _writeConstructor(IndentableStringBuffer buffer, Interface interface) {
+  final allFields = _getAllFields(interface);
+  if (allFields.isEmpty) {
+    return;
+  }
+  buffer
+    ..writeIndented('${interface.name}(')
+    ..write(allFields.map((field) => 'this.${field.name}').join(', '))
+    ..writeln(');');
+}
+
 void _writeDocCommentsAndAnnotations(
     IndentableStringBuffer buffer, ApiItem item) {
   var comment = item.comment?.trim();
@@ -139,6 +165,36 @@
   }
 }
 
+void _writeEnumClass(IndentableStringBuffer buffer, Namespace namespace) {
+  _writeDocCommentsAndAnnotations(buffer, namespace);
+  buffer
+    ..writeln('class ${namespace.name} {')
+    ..indent()
+    ..writeIndentedln('const ${namespace.name}._(this._value);')
+    ..writeln()
+    ..writeIndentedln('final Object _value;')
+    ..writeln();
+  namespace.members.whereType<Const>().forEach((cons) {
+    _writeDocCommentsAndAnnotations(buffer, cons);
+    buffer
+      ..writeIndentedln(
+          'static const ${_makeValidIdentifier(cons.name)} = const ${namespace.name}._(${cons.value});');
+  });
+  buffer
+    ..writeln()
+    ..writeIndentedln('Object toJson() => _value;')
+    ..writeln()
+    ..writeIndentedln('@override String toString() => _value.toString();')
+    ..writeln()
+    ..writeIndentedln('@override get hashCode => _value.hashCode;')
+    ..writeln()
+    ..writeIndentedln(
+        'bool operator ==(o) => o is ${namespace.name} && o._value == _value;')
+    ..outdent()
+    ..writeln('}')
+    ..writeln();
+}
+
 void _writeField(IndentableStringBuffer buffer, Field field) {
   _writeDocCommentsAndAnnotations(buffer, field);
   buffer
@@ -147,32 +203,6 @@
     ..writeln(' ${field.name};');
 }
 
-/// Recursively gets all members from superclasses.
-List<Field> _getAllFields(Interface interface) {
-  // Handle missing interfaces (such as special cased interfaces that won't
-  // be included in this model).
-  if (interface == null) {
-    return [];
-  }
-  return interface.members
-      .whereType<Field>()
-      .followedBy(interface.baseTypes
-          .map((name) => _getAllFields(_interfaces[name]))
-          .expand((ts) => ts))
-      .toList();
-}
-
-void _writeConstructor(IndentableStringBuffer buffer, Interface interface) {
-  final allFields = _getAllFields(interface);
-  if (allFields.isEmpty) {
-    return;
-  }
-  buffer
-    ..writeIndented('${interface.name}(')
-    ..write(allFields.map((field) => 'this.${field.name}').join(', '))
-    ..writeln(');');
-}
-
 void _writeInterface(IndentableStringBuffer buffer, Interface interface) {
   _writeDocCommentsAndAnnotations(buffer, interface);
 
@@ -279,36 +309,6 @@
     ..writeIndentedln('}');
 }
 
-void _writeEnumClass(IndentableStringBuffer buffer, Namespace namespace) {
-  _writeDocCommentsAndAnnotations(buffer, namespace);
-  buffer
-    ..writeln('class ${namespace.name} {')
-    ..indent()
-    ..writeIndentedln('const ${namespace.name}._(this._value);')
-    ..writeln()
-    ..writeIndentedln('final Object _value;')
-    ..writeln();
-  namespace.members.whereType<Const>().forEach((cons) {
-    _writeDocCommentsAndAnnotations(buffer, cons);
-    buffer
-      ..writeIndentedln(
-          'static const ${_makeValidIdentifier(cons.name)} = const ${namespace.name}._(${cons.value});');
-  });
-  buffer
-    ..writeln()
-    ..writeIndentedln('Object toJson() => _value;')
-    ..writeln()
-    ..writeIndentedln('@override String toString() => _value.toString();')
-    ..writeln()
-    ..writeIndentedln('@override get hashCode => _value.hashCode;')
-    ..writeln()
-    ..writeIndentedln(
-        'bool operator ==(o) => o is ${namespace.name} && o._value == _value;')
-    ..outdent()
-    ..writeln('}')
-    ..writeln();
-}
-
 void _writeType(IndentableStringBuffer buffer, ApiItem type) {
   if (type is Interface) {
     _writeInterface(buffer, type);
@@ -339,14 +339,14 @@
     write(obj);
   }
 
+  void writeIndentedln(Object obj) {
+    write(_indentString);
+    writeln(obj);
+  }
+
   void writeIndentedlnIf(bool condition, Object obj) {
     if (condition) {
       writeIndentedln(obj);
     }
   }
-
-  void writeIndentedln(Object obj) {
-    write(_indentString);
-    writeln(obj);
-  }
 }
diff --git a/pkg/analysis_server/tool/lsp_spec/generate_all.dart b/pkg/analysis_server/tool/lsp_spec/generate_all.dart
index 1b5c45e..caa6aea 100644
--- a/pkg/analysis_server/tool/lsp_spec/generate_all.dart
+++ b/pkg/analysis_server/tool/lsp_spec/generate_all.dart
@@ -12,21 +12,6 @@
 import 'markdown.dart';
 import 'typescript.dart';
 
-const _generatedFileHeader = '''
-// Copyright (c) 2018, 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.
-
-// This file has been automatically generated. Please do not edit it manually.
-// To regenerate the file, use the script
-// "pkg/analysis_server/tool/lsp_spec/generate_all.dart".
-
-import 'dart:core' hide deprecated;
-import 'dart:core' as core show deprecated;
-import 'package:analysis_server/lsp_protocol/protocol_special.dart';
-
-''';
-
 main() async {
   final String script = Platform.script.toFilePath();
   // 3x parent = file -> lsp_spec -> tool -> analysis_server.
@@ -43,6 +28,21 @@
       .writeAsStringSync(_generatedFileHeader + output);
 }
 
+const _generatedFileHeader = '''
+// Copyright (c) 2018, 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.
+
+// This file has been automatically generated. Please do not edit it manually.
+// To regenerate the file, use the script
+// "pkg/analysis_server/tool/lsp_spec/generate_all.dart".
+
+import 'dart:core' hide deprecated;
+import 'dart:core' as core show deprecated;
+import 'package:analysis_server/lsp_protocol/protocol_special.dart';
+
+''';
+
 final Uri specUri = Uri.parse(
     'https://raw.githubusercontent.com/Microsoft/language-server-protocol/gh-pages/specification.md');
 
diff --git a/pkg/analysis_server/tool/lsp_spec/typescript.dart b/pkg/analysis_server/tool/lsp_spec/typescript.dart
index 40ec412..286b0e2 100644
--- a/pkg/analysis_server/tool/lsp_spec/typescript.dart
+++ b/pkg/analysis_server/tool/lsp_spec/typescript.dart
@@ -18,14 +18,6 @@
   return types;
 }
 
-/// Removes types that are in the spec that we don't want.
-void _removeUnwantedTypes(List<ApiItem> types) {
-  // These types are not used for v3.0 (Feb 2017) and by dropping them we don't
-  // have to handle any cases where both a namespace and interfaces are declared
-  // with the same name.
-  types.removeWhere((item) => item.name == 'InitializeError');
-}
-
 String _cleanComment(String comment) {
   if (comment == null) {
     return null;
@@ -46,6 +38,50 @@
   return comment.trim();
 }
 
+/// Fixes up some enum types that are not as specific as they could be in the
+/// spec. For example, Diagnostic.severity is typed "number" but can be mapped
+/// to the DiagnosticSeverity enum class.
+String _getImprovedType(String interfaceName, String fieldName) {
+  const Map<String, Map<String, String>> _improvedTypeMappings = {
+    "Diagnostic": {
+      "severity": "DiagnosticSeverity",
+    },
+    "TextDocumentSyncOptions": {
+      "change": "TextDocumentSyncKind",
+    },
+    "FileSystemWatcher": {
+      "kind": "WatchKind",
+    },
+    "CompletionItem": {
+      "kind": "CompletionItemKind",
+    },
+    "DocumentHighlight": {
+      "kind": "DocumentHighlightKind",
+    },
+    "FoldingRange": {
+      "kind": "FoldingRangeKind",
+    },
+  };
+
+  final interface = _improvedTypeMappings[interfaceName];
+
+  return interface != null ? interface[fieldName] : null;
+}
+
+List<String> _getSpecialBaseClasses(String name) {
+  const fileOperationTypes = [
+    'TextDocumentEdit',
+    'CreateFile',
+    'RenameFile',
+    'DeleteFile'
+  ];
+  if (fileOperationTypes.contains(name)) {
+    return ['FileOperation'];
+  } else {
+    return [];
+  }
+}
+
 List<String> _parseTypes(String baseTypes, String sep) {
   // Special case for a single complicated type we can't parse easily...
   if (baseTypes ==
@@ -55,6 +91,14 @@
   return baseTypes?.split(sep)?.map((t) => t.trim())?.toList() ?? [];
 }
 
+/// Removes types that are in the spec that we don't want.
+void _removeUnwantedTypes(List<ApiItem> types) {
+  // These types are not used for v3.0 (Feb 2017) and by dropping them we don't
+  // have to handle any cases where both a namespace and interfaces are declared
+  // with the same name.
+  types.removeWhere((item) => item.name == 'InitializeError');
+}
+
 /// Base class for Interface, Field, Constant, etc. parsed from the LSP spec.
 abstract class ApiItem {
   String name, comment;
@@ -195,50 +239,6 @@
   }
 }
 
-List<String> _getSpecialBaseClasses(String name) {
-  const fileOperationTypes = [
-    'TextDocumentEdit',
-    'CreateFile',
-    'RenameFile',
-    'DeleteFile'
-  ];
-  if (fileOperationTypes.contains(name)) {
-    return ['FileOperation'];
-  } else {
-    return [];
-  }
-}
-
-/// Fixes up some enum types that are not as specific as they could be in the
-/// spec. For example, Diagnostic.severity is typed "number" but can be mapped
-/// to the DiagnosticSeverity enum class.
-String _getImprovedType(String interfaceName, String fieldName) {
-  const Map<String, Map<String, String>> _improvedTypeMappings = {
-    "Diagnostic": {
-      "severity": "DiagnosticSeverity",
-    },
-    "TextDocumentSyncOptions": {
-      "change": "TextDocumentSyncKind",
-    },
-    "FileSystemWatcher": {
-      "kind": "WatchKind",
-    },
-    "CompletionItem": {
-      "kind": "CompletionItemKind",
-    },
-    "DocumentHighlight": {
-      "kind": "DocumentHighlightKind",
-    },
-    "FoldingRange": {
-      "kind": "FoldingRangeKind",
-    },
-  };
-
-  final interface = _improvedTypeMappings[interfaceName];
-
-  return interface != null ? interface[fieldName] : null;
-}
-
 /// A Field or Constant parsed from the LSP type.
 abstract class Member extends ApiItem {
   Member(String name, String comment) : super(name, comment);
@@ -263,20 +263,6 @@
     return enums;
   }
 
-  static List<Namespace> _extractNamespacesFrom(String code) {
-    final RegExp _namespacePattern = new RegExp(
-        _comment + r'(?:export\s+)?namespace\s+(\w+)\s*' + _blockBody);
-
-    final namespaces = _namespacePattern.allMatches(code).map((match) {
-      final String comment = match.group(1);
-      final String name = match.group(2);
-      final String body = match.group(3);
-      final List<Member> members = Member.extractFrom(name, body);
-      return new Namespace(name, comment, members);
-    }).toList();
-    return namespaces;
-  }
-
   static List<Namespace> _extractEnumsFrom(String code) {
     final RegExp _namespacePattern =
         new RegExp(_comment + r'(?:export\s+)?enum\s+(\w+)\s*' + _blockBody);
@@ -291,6 +277,20 @@
     }).toList();
     return namespaces;
   }
+
+  static List<Namespace> _extractNamespacesFrom(String code) {
+    final RegExp _namespacePattern = new RegExp(
+        _comment + r'(?:export\s+)?namespace\s+(\w+)\s*' + _blockBody);
+
+    final namespaces = _namespacePattern.allMatches(code).map((match) {
+      final String comment = match.group(1);
+      final String name = match.group(2);
+      final String body = match.group(3);
+      final List<Member> members = Member.extractFrom(name, body);
+      return new Namespace(name, comment, members);
+    }).toList();
+    return namespaces;
+  }
 }
 
 /// A type alias parsed from the LSP spec.