Chromium Code Reviews| OLD | NEW |
|---|---|
| 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'; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 formattedResult.selectionLength).toResponse(request.id); | 110 formattedResult.selectionLength).toResponse(request.id); |
| 111 } | 111 } |
| 112 | 112 |
| 113 Response getAssists(Request request) { | 113 Response getAssists(Request request) { |
| 114 var params = new EditGetAssistsParams.fromRequest(request); | 114 var params = new EditGetAssistsParams.fromRequest(request); |
| 115 List<SourceChange> changes = <SourceChange>[]; | 115 List<SourceChange> changes = <SourceChange>[]; |
| 116 List<CompilationUnit> units = | 116 List<CompilationUnit> units = |
| 117 server.getResolvedCompilationUnits(params.file); | 117 server.getResolvedCompilationUnits(params.file); |
| 118 if (units.isNotEmpty) { | 118 if (units.isNotEmpty) { |
| 119 CompilationUnit unit = units[0]; | 119 CompilationUnit unit = units[0]; |
| 120 List<Assist> assists = | 120 List<Assist> assists = computeAssists(unit, params.offset, params.length); |
| 121 computeAssists(searchEngine, unit, params.offset, params.length); | |
| 122 assists.forEach((Assist assist) { | 121 assists.forEach((Assist assist) { |
| 123 changes.add(assist.change); | 122 changes.add(assist.change); |
| 124 }); | 123 }); |
| 125 } | 124 } |
| 126 // respond | 125 // respond |
| 127 return new EditGetAssistsResult(changes).toResponse(request.id); | 126 return new EditGetAssistsResult(changes).toResponse(request.id); |
| 128 } | 127 } |
| 129 | 128 |
| 130 Response getAvailableRefactorings(Request request) { | 129 Response getAvailableRefactorings(Request request) { |
| 130 if (searchEngine == null) { | |
|
Brian Wilkerson
2015/02/17 19:57:36
Would it be better to check 'index' in these cases
scheglov
2015/02/17 20:01:02
Well, there is some inconsistency here.
We don't u
| |
| 131 return new Response.noIndexGenerated(request); | |
| 132 } | |
| 133 // prepare parameters | |
| 131 var params = new EditGetAvailableRefactoringsParams.fromRequest(request); | 134 var params = new EditGetAvailableRefactoringsParams.fromRequest(request); |
| 132 String file = params.file; | 135 String file = params.file; |
| 133 int offset = params.offset; | 136 int offset = params.offset; |
| 134 int length = params.length; | 137 int length = params.length; |
| 135 // add refactoring kinds | 138 // add refactoring kinds |
| 136 List<RefactoringKind> kinds = <RefactoringKind>[]; | 139 List<RefactoringKind> kinds = <RefactoringKind>[]; |
| 137 // try EXTRACT_* | 140 // try EXTRACT_* |
| 138 if (length != 0) { | 141 if (length != 0) { |
| 139 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); | 142 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); |
| 140 kinds.add(RefactoringKind.EXTRACT_METHOD); | 143 kinds.add(RefactoringKind.EXTRACT_METHOD); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 163 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; | 166 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; |
| 164 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); | 167 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); |
| 165 for (CompilationUnit unit in units) { | 168 for (CompilationUnit unit in units) { |
| 166 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); | 169 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); |
| 167 if (errorInfo != null) { | 170 if (errorInfo != null) { |
| 168 LineInfo lineInfo = errorInfo.lineInfo; | 171 LineInfo lineInfo = errorInfo.lineInfo; |
| 169 int requestLine = lineInfo.getLocation(offset).lineNumber; | 172 int requestLine = lineInfo.getLocation(offset).lineNumber; |
| 170 for (engine.AnalysisError error in errorInfo.errors) { | 173 for (engine.AnalysisError error in errorInfo.errors) { |
| 171 int errorLine = lineInfo.getLocation(error.offset).lineNumber; | 174 int errorLine = lineInfo.getLocation(error.offset).lineNumber; |
| 172 if (errorLine == requestLine) { | 175 if (errorLine == requestLine) { |
| 173 List<Fix> fixes = computeFixes(searchEngine, unit, error); | 176 List<Fix> fixes = computeFixes(unit, error); |
| 174 if (fixes.isNotEmpty) { | 177 if (fixes.isNotEmpty) { |
| 175 AnalysisError serverError = | 178 AnalysisError serverError = |
| 176 newAnalysisError_fromEngine(lineInfo, error); | 179 newAnalysisError_fromEngine(lineInfo, error); |
| 177 AnalysisErrorFixes errorFixes = | 180 AnalysisErrorFixes errorFixes = |
| 178 new AnalysisErrorFixes(serverError); | 181 new AnalysisErrorFixes(serverError); |
| 179 errorFixesList.add(errorFixes); | 182 errorFixesList.add(errorFixes); |
| 180 fixes.forEach((fix) { | 183 fixes.forEach((fix) { |
| 181 errorFixes.fixes.add(fix.change); | 184 errorFixes.fixes.add(fix.change); |
| 182 }); | 185 }); |
| 183 } | 186 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // do sort | 246 // do sort |
| 244 int fileStamp = context.getModificationStamp(source); | 247 int fileStamp = context.getModificationStamp(source); |
| 245 String code = context.getContents(source).data; | 248 String code = context.getContents(source).data; |
| 246 MemberSorter sorter = new MemberSorter(code, unit); | 249 MemberSorter sorter = new MemberSorter(code, unit); |
| 247 List<SourceEdit> edits = sorter.sort(); | 250 List<SourceEdit> edits = sorter.sort(); |
| 248 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits); | 251 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits); |
| 249 return new EditSortMembersResult(fileEdit).toResponse(request.id); | 252 return new EditSortMembersResult(fileEdit).toResponse(request.id); |
| 250 } | 253 } |
| 251 | 254 |
| 252 Response _getRefactoring(Request request) { | 255 Response _getRefactoring(Request request) { |
| 256 if (searchEngine == null) { | |
| 257 return new Response.noIndexGenerated(request); | |
| 258 } | |
| 253 if (refactoringManager.hasPendingRequest) { | 259 if (refactoringManager.hasPendingRequest) { |
| 254 refactoringManager.cancel(); | 260 refactoringManager.cancel(); |
| 255 _newRefactoringManager(); | 261 _newRefactoringManager(); |
| 256 } | 262 } |
| 257 refactoringManager.getRefactoring(request); | 263 refactoringManager.getRefactoring(request); |
| 258 return Response.DELAYED_RESPONSE; | 264 return Response.DELAYED_RESPONSE; |
| 259 } | 265 } |
| 260 | 266 |
| 261 /** | 267 /** |
| 262 * Initializes [refactoringManager] with a new instance. | 268 * Initializes [refactoringManager] with a new instance. |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 } | 619 } |
| 614 if (refactoring is RenameRefactoring) { | 620 if (refactoring is RenameRefactoring) { |
| 615 RenameRefactoring renameRefactoring = refactoring; | 621 RenameRefactoring renameRefactoring = refactoring; |
| 616 RenameOptions renameOptions = params.options; | 622 RenameOptions renameOptions = params.options; |
| 617 renameRefactoring.newName = renameOptions.newName; | 623 renameRefactoring.newName = renameOptions.newName; |
| 618 return renameRefactoring.checkNewName(); | 624 return renameRefactoring.checkNewName(); |
| 619 } | 625 } |
| 620 return new RefactoringStatus(); | 626 return new RefactoringStatus(); |
| 621 } | 627 } |
| 622 } | 628 } |
| OLD | NEW |