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

Side by Side Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 833903005: Analysis server format service wiring (and protocol doc update). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/lib/src/generated_protocol.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library edit.domain; 5 library edit.domain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/collections.dart'; 10 import 'package:analysis_server/src/collections.dart';
11 import 'package:analysis_server/src/constants.dart'; 11 import 'package:analysis_server/src/constants.dart';
12 import 'package:analysis_server/src/protocol_server.dart' hide Element; 12 import 'package:analysis_server/src/protocol_server.dart' hide Element;
13 import 'package:analysis_server/src/services/correction/assist.dart'; 13 import 'package:analysis_server/src/services/correction/assist.dart';
14 import 'package:analysis_server/src/services/correction/fix.dart'; 14 import 'package:analysis_server/src/services/correction/fix.dart';
15 import 'package:analysis_server/src/services/correction/sort_members.dart'; 15 import 'package:analysis_server/src/services/correction/sort_members.dart';
16 import 'package:analysis_server/src/services/correction/status.dart'; 16 import 'package:analysis_server/src/services/correction/status.dart';
17 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
18 import 'package:analysis_server/src/services/search/search_engine.dart'; 18 import 'package:analysis_server/src/services/search/search_engine.dart';
19 import 'package:analyzer/src/generated/ast.dart'; 19 import 'package:analyzer/src/generated/ast.dart';
20 import 'package:analyzer/src/generated/element.dart'; 20 import 'package:analyzer/src/generated/element.dart';
21 import 'package:analyzer/src/generated/engine.dart' as engine; 21 import 'package:analyzer/src/generated/engine.dart' as engine;
22 import 'package:analyzer/src/generated/error.dart' as engine; 22 import 'package:analyzer/src/generated/error.dart' as engine;
23 import 'package:analyzer/src/generated/parser.dart' as engine; 23 import 'package:analyzer/src/generated/parser.dart' as engine;
24 import 'package:analyzer/src/generated/scanner.dart' as engine; 24 import 'package:analyzer/src/generated/scanner.dart' as engine;
25 import 'package:analyzer/src/generated/source.dart'; 25 import 'package:analyzer/src/generated/source.dart';
26 import 'package:dart_style/dart_style.dart';
26 27
27 28
28 bool test_simulateRefactoringException_change = false; 29 bool test_simulateRefactoringException_change = false;
29 bool test_simulateRefactoringException_final = false; 30 bool test_simulateRefactoringException_final = false;
30 bool test_simulateRefactoringException_init = false; 31 bool test_simulateRefactoringException_init = false;
31 32
32 33
33 /** 34 /**
34 * Instances of the class [EditDomainHandler] implement a [RequestHandler] 35 * Instances of the class [EditDomainHandler] implement a [RequestHandler]
35 * that handles requests in the edit domain. 36 * that handles requests in the edit domain.
(...skipping 13 matching lines...) Expand all
49 50
50 /** 51 /**
51 * Initialize a newly created handler to handle requests for the given [server ]. 52 * Initialize a newly created handler to handle requests for the given [server ].
52 */ 53 */
53 EditDomainHandler(this.server) { 54 EditDomainHandler(this.server) {
54 searchEngine = server.searchEngine; 55 searchEngine = server.searchEngine;
55 refactoringManager = new _RefactoringManager(server, searchEngine); 56 refactoringManager = new _RefactoringManager(server, searchEngine);
56 } 57 }
57 58
58 Response format(Request request) { 59 Response format(Request request) {
59 throw new RequestFailure(
60 new Response.unsupportedFeature(
61 request.id,
62 'The edit.format request is not yet supported'));
63 60
64 // EditFormatParams params = new EditFormatParams.fromRequest(request); 61 EditFormatParams params = new EditFormatParams.fromRequest(request);
65 // String file = params.file; 62 String file = params.file;
66 // int initialOffset = params.selectionOffset; 63
67 // int initialLength = params.selectionLength; 64 engine.AnalysisContext context = server.getAnalysisContext(file);
68 // 65 if (context == null) {
69 // List<SourceEdit> edits = <SourceEdit>[]; 66 return new Response.formatInvalidFile(request);
70 // int finalOffset = initialOffset; 67 }
71 // int finalLength = initialLength; 68
72 // return new EditFormatResult(edits, finalOffset, finalLength).toResponse(re quest.id); 69 Source source = server.getSource(file);
70 engine.TimestampedData<String> contents;
71 try {
72 contents = context.getContents(source);
73 } catch (e) {
74 return new Response.formatInvalidFile(request);
75 }
76 String unformattedSource = contents.data;
77
78 SourceCode code = new SourceCode(
79 unformattedSource,
80 uri: null,
81 isCompilationUnit: true,
82 selectionStart: params.selectionOffset,
83 selectionLength: params.selectionLength);
84 DartFormatter formatter = new DartFormatter();
85 SourceCode formattedResult = formatter.formatSource(code);
86 String formattedSource = formattedResult.text;
87
88 List<SourceEdit> edits = <SourceEdit>[];
89
90 if (formattedSource != unformattedSource) {
91 //TODO: replace full replacements with smaller, more targeted edits
92 SourceEdit edit =
93 new SourceEdit(0, unformattedSource.length, formattedSource);
94 edits.add(edit);
95 }
96
97 return new EditFormatResult(
98 edits,
99 formattedResult.selectionStart,
100 formattedResult.selectionLength).toResponse(request.id);
73 } 101 }
74 102
75 Response getAssists(Request request) { 103 Response getAssists(Request request) {
76 var params = new EditGetAssistsParams.fromRequest(request); 104 var params = new EditGetAssistsParams.fromRequest(request);
77 List<SourceChange> changes = <SourceChange>[]; 105 List<SourceChange> changes = <SourceChange>[];
78 List<CompilationUnit> units = 106 List<CompilationUnit> units =
79 server.getResolvedCompilationUnits(params.file); 107 server.getResolvedCompilationUnits(params.file);
80 if (units.isNotEmpty) { 108 if (units.isNotEmpty) {
81 CompilationUnit unit = units[0]; 109 CompilationUnit unit = units[0];
82 List<Assist> assists = 110 List<Assist> assists =
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 572 }
545 if (refactoring is RenameRefactoring) { 573 if (refactoring is RenameRefactoring) {
546 RenameRefactoring renameRefactoring = refactoring; 574 RenameRefactoring renameRefactoring = refactoring;
547 RenameOptions renameOptions = params.options; 575 RenameOptions renameOptions = params.options;
548 renameRefactoring.newName = renameOptions.newName; 576 renameRefactoring.newName = renameOptions.newName;
549 return renameRefactoring.checkNewName(); 577 return renameRefactoring.checkNewName();
550 } 578 }
551 return new RefactoringStatus(); 579 return new RefactoringStatus();
552 } 580 }
553 } 581 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/lib/src/generated_protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698