@@ -7,7 +7,7 @@ import 'dart:io' as io;
7
7
import 'dart:io' ;
8
8
9
9
import 'package:analysis_server/lsp_protocol/protocol.dart' as lsp
10
- show MessageType;
10
+ show MessageType, OptionalVersionedTextDocumentIdentifier ;
11
11
import 'package:analysis_server/src/analytics/analytics_manager.dart' ;
12
12
import 'package:analysis_server/src/collections.dart' ;
13
13
import 'package:analysis_server/src/context_manager.dart' ;
@@ -29,6 +29,7 @@ import 'package:analysis_server/src/services/correction/namespace.dart';
29
29
import 'package:analysis_server/src/services/pub/pub_api.dart' ;
30
30
import 'package:analysis_server/src/services/pub/pub_command.dart' ;
31
31
import 'package:analysis_server/src/services/pub/pub_package_service.dart' ;
32
+ import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart' ;
32
33
import 'package:analysis_server/src/services/search/element_visitors.dart' ;
33
34
import 'package:analysis_server/src/services/search/search_engine.dart' ;
34
35
import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
@@ -49,6 +50,7 @@ import 'package:analyzer/file_system/file_system.dart';
49
50
import 'package:analyzer/file_system/overlay_file_system.dart' ;
50
51
import 'package:analyzer/file_system/physical_file_system.dart' ;
51
52
import 'package:analyzer/instrumentation/instrumentation.dart' ;
53
+ import 'package:analyzer/source/line_info.dart' ;
52
54
import 'package:analyzer/src/dart/analysis/byte_store.dart' ;
53
55
import 'package:analyzer/src/dart/analysis/driver.dart' as analysis;
54
56
import 'package:analyzer/src/dart/analysis/driver.dart' ;
@@ -202,6 +204,10 @@ abstract class AnalysisServer {
202
204
/// Starts completed and will be replaced each time a context rebuild starts.
203
205
Completer <void > analysisContextRebuildCompleter = Completer ()..complete ();
204
206
207
+ /// The workspace for rename refactorings.
208
+ late final refactoringWorkspace =
209
+ RefactoringWorkspace (driverMap.values, searchEngine);
210
+
205
211
AnalysisServer (
206
212
this .options,
207
213
this .sdkManager,
@@ -477,6 +483,9 @@ abstract class AnalysisServer {
477
483
DartdocDirectiveInfo ();
478
484
}
479
485
486
+ /// Gets the current version number of a document (if known).
487
+ int ? getDocumentVersion (String path);
488
+
480
489
/// Return a [Future] that completes with the [Element] at the given
481
490
/// [offset] of the given [file] , or with `null` if there is no node at the
482
491
/// [offset] or the node does not have an element.
@@ -524,6 +533,25 @@ abstract class AnalysisServer {
524
533
return element;
525
534
}
526
535
536
+ /// Return a [LineInfo] for the file with the given [path] .
537
+ ///
538
+ /// If the file does not exist or cannot be read, returns `null` .
539
+ ///
540
+ /// This method supports non-Dart files but uses the current content of the
541
+ /// file which may not be the latest analyzed version of the file if it was
542
+ /// recently modified, so using the lineInfo from an analyzed result may be
543
+ /// preferable.
544
+ LineInfo ? getLineInfo (String path) {
545
+ try {
546
+ final content = resourceProvider.getFile (path).readAsStringSync ();
547
+ return LineInfo .fromContent (content);
548
+ } on FileSystemException {
549
+ // If the file does not exist or cannot be read, return null to allow
550
+ // the caller to decide how to handle this.
551
+ return null ;
552
+ }
553
+ }
554
+
527
555
/// Return a [Future] that completes with the resolved [AstNode] at the
528
556
/// given [offset] of the given [file] , or with `null` if there is no node as
529
557
/// the [offset] .
@@ -606,6 +634,16 @@ abstract class AnalysisServer {
606
634
});
607
635
}
608
636
637
+ /// Gets the version of a document known to the server, returning a
638
+ /// [lsp.OptionalVersionedTextDocumentIdentifier] with a version of `null` if the
639
+ /// document version is not known.
640
+ lsp.OptionalVersionedTextDocumentIdentifier getVersionedDocumentIdentifier (
641
+ String path) {
642
+ return lsp.OptionalVersionedTextDocumentIdentifier (
643
+ uri: resourceProvider.pathContext.toUri (path),
644
+ version: getDocumentVersion (path));
645
+ }
646
+
609
647
@mustCallSuper
610
648
FutureOr <void > handleAnalysisStatusChange (analysis.AnalysisStatus status) {
611
649
if (isFirstAnalysisSinceContextsBuilt && ! status.isAnalyzing) {
0 commit comments