mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:37:53 +00:00
[Analyzer] Return GET_FIXES_INVALID_FILE for getFixes requests for files outside roots
Bug: https://github.com/dart-lang/sdk/issues/43521 Change-Id: I250bca1131b3d8bc7f8232db82f7f03008b3db48 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164088 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Danny Tuppeny <danny@tuppeny.com>
This commit is contained in:
parent
15dc3100cc
commit
c2e8d1df06
|
@ -109,7 +109,7 @@ a:focus, a:hover {
|
|||
<body>
|
||||
<h1>Analysis Server API Specification</h1>
|
||||
<h1 style="color:#999999">Version
|
||||
1.29.0
|
||||
1.29.1
|
||||
</h1>
|
||||
<p>
|
||||
This document contains a specification of the API provided by the
|
||||
|
@ -2267,6 +2267,13 @@ a:focus, a:hover {
|
|||
Return the set of fixes that are available for the errors at
|
||||
a given offset in a given file.
|
||||
</p>
|
||||
<p>
|
||||
If a request is made for a file which does not exist, or
|
||||
which is not currently subject to analysis (e.g. because it
|
||||
is not associated with any analysis root specified to
|
||||
analysis.setAnalysisRoots), an error of type
|
||||
<tt>GET_FIXES_INVALID_FILE</tt> will be generated.
|
||||
</p>
|
||||
|
||||
|
||||
<h4>parameters:</h4><dl><dt class="field"><b>file: <a href="#type_FilePath">FilePath</a></b></dt><dd>
|
||||
|
@ -5216,6 +5223,13 @@ a:focus, a:hover {
|
|||
which does not match a file currently subject to
|
||||
analysis.
|
||||
</p>
|
||||
</dd><dt class="value">GET_FIXES_INVALID_FILE</dt><dd>
|
||||
|
||||
<p>
|
||||
An "edit.getFixes" request specified a FilePath
|
||||
which does not match a file currently subject to
|
||||
analysis.
|
||||
</p>
|
||||
</dd><dt class="value">GET_IMPORTED_ELEMENTS_INVALID_FILE</dt><dd>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -365,6 +365,13 @@ class Response {
|
|||
error: RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE,
|
||||
'Error during `analysis.getErrors`: invalid file.'));
|
||||
|
||||
/// Initialize a newly created instance to represent the
|
||||
/// GET_FIXES_INVALID_FILE error condition.
|
||||
Response.getFixesInvalidFile(Request request)
|
||||
: this(request.id,
|
||||
error: RequestError(RequestErrorCode.GET_FIXES_INVALID_FILE,
|
||||
'Error during `edit.getFixes`: invalid file.'));
|
||||
|
||||
/// Initialize a newly created instance to represent the
|
||||
/// GET_IMPORTED_ELEMENTS_INVALID_FILE error condition.
|
||||
Response.getImportedElementsInvalidFile(Request request)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// To regenerate the file, use the script
|
||||
// "pkg/analysis_server/tool/spec/generate_files".
|
||||
|
||||
const String PROTOCOL_VERSION = '1.29.0';
|
||||
const String PROTOCOL_VERSION = '1.29.1';
|
||||
|
||||
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
|
||||
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';
|
||||
|
|
|
@ -17810,6 +17810,7 @@ class RequestError implements HasToJson {
|
|||
/// FORMAT_INVALID_FILE
|
||||
/// FORMAT_WITH_ERRORS
|
||||
/// GET_ERRORS_INVALID_FILE
|
||||
/// GET_FIXES_INVALID_FILE
|
||||
/// GET_IMPORTED_ELEMENTS_INVALID_FILE
|
||||
/// GET_KYTHE_ENTRIES_INVALID_FILE
|
||||
/// GET_NAVIGATION_INVALID_FILE
|
||||
|
@ -17891,6 +17892,11 @@ class RequestErrorCode implements Enum {
|
|||
static const RequestErrorCode GET_ERRORS_INVALID_FILE =
|
||||
RequestErrorCode._('GET_ERRORS_INVALID_FILE');
|
||||
|
||||
/// An "edit.getFixes" request specified a FilePath which does not match a
|
||||
/// file currently subject to analysis.
|
||||
static const RequestErrorCode GET_FIXES_INVALID_FILE =
|
||||
RequestErrorCode._('GET_FIXES_INVALID_FILE');
|
||||
|
||||
/// An "analysis.getImportedElements" request specified a FilePath that does
|
||||
/// not match a file currently subject to analysis.
|
||||
static const RequestErrorCode GET_IMPORTED_ELEMENTS_INVALID_FILE =
|
||||
|
@ -18022,6 +18028,7 @@ class RequestErrorCode implements Enum {
|
|||
FORMAT_INVALID_FILE,
|
||||
FORMAT_WITH_ERRORS,
|
||||
GET_ERRORS_INVALID_FILE,
|
||||
GET_FIXES_INVALID_FILE,
|
||||
GET_IMPORTED_ELEMENTS_INVALID_FILE,
|
||||
GET_KYTHE_ENTRIES_INVALID_FILE,
|
||||
GET_NAVIGATION_INVALID_FILE,
|
||||
|
@ -18076,6 +18083,8 @@ class RequestErrorCode implements Enum {
|
|||
return FORMAT_WITH_ERRORS;
|
||||
case 'GET_ERRORS_INVALID_FILE':
|
||||
return GET_ERRORS_INVALID_FILE;
|
||||
case 'GET_FIXES_INVALID_FILE':
|
||||
return GET_FIXES_INVALID_FILE;
|
||||
case 'GET_IMPORTED_ELEMENTS_INVALID_FILE':
|
||||
return GET_IMPORTED_ELEMENTS_INVALID_FILE;
|
||||
case 'GET_KYTHE_ENTRIES_INVALID_FILE':
|
||||
|
|
|
@ -280,6 +280,12 @@ class EditDomainHandler extends AbstractRequestHandler {
|
|||
if (server.sendResponseErrorIfInvalidFilePath(request, file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!server.contextManager.isInAnalysisRoot(file)) {
|
||||
server.sendResponse(Response.getFixesInvalidFile(request));
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Allow plugins to start computing fixes.
|
||||
//
|
||||
|
|
|
@ -29,6 +29,24 @@ class FixesTest extends AbstractAnalysisTest {
|
|||
handler = EditDomainHandler(server);
|
||||
}
|
||||
|
||||
Future<void> test_fileOutsideRoot() async {
|
||||
final outsideFile = '/foo/test.dart';
|
||||
newFile(outsideFile, content: 'bad code to create error');
|
||||
|
||||
// Set up the original project, as the code fix code won't run at all
|
||||
// if there are no contexts.
|
||||
createProject();
|
||||
await waitForTasksFinished();
|
||||
|
||||
var request =
|
||||
EditGetFixesParams(convertPath(outsideFile), 0).toRequest('0');
|
||||
var response = await waitResponse(request);
|
||||
expect(
|
||||
response,
|
||||
isResponseFailure('0', RequestErrorCode.GET_FIXES_INVALID_FILE),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_fixUndefinedClass() async {
|
||||
createProject();
|
||||
addTestFile('''
|
||||
|
|
|
@ -1708,6 +1708,11 @@ abstract class IntegrationTestMixin {
|
|||
/// Return the set of fixes that are available for the errors at a given
|
||||
/// offset in a given file.
|
||||
///
|
||||
/// If a request is made for a file which does not exist, or which is not
|
||||
/// currently subject to analysis (e.g. because it is not associated with any
|
||||
/// analysis root specified to analysis.setAnalysisRoots), an error of type
|
||||
/// GET_FIXES_INVALID_FILE will be generated.
|
||||
///
|
||||
/// Parameters
|
||||
///
|
||||
/// file: FilePath
|
||||
|
|
|
@ -1365,6 +1365,7 @@ final Matcher isRequestError = LazyMatcher(() => MatchesJsonObject(
|
|||
/// FORMAT_INVALID_FILE
|
||||
/// FORMAT_WITH_ERRORS
|
||||
/// GET_ERRORS_INVALID_FILE
|
||||
/// GET_FIXES_INVALID_FILE
|
||||
/// GET_IMPORTED_ELEMENTS_INVALID_FILE
|
||||
/// GET_KYTHE_ENTRIES_INVALID_FILE
|
||||
/// GET_NAVIGATION_INVALID_FILE
|
||||
|
@ -1401,6 +1402,7 @@ final Matcher isRequestErrorCode = MatchesEnum('RequestErrorCode', [
|
|||
'FORMAT_INVALID_FILE',
|
||||
'FORMAT_WITH_ERRORS',
|
||||
'GET_ERRORS_INVALID_FILE',
|
||||
'GET_FIXES_INVALID_FILE',
|
||||
'GET_IMPORTED_ELEMENTS_INVALID_FILE',
|
||||
'GET_KYTHE_ENTRIES_INVALID_FILE',
|
||||
'GET_NAVIGATION_INVALID_FILE',
|
||||
|
|
|
@ -574,6 +574,10 @@ public interface AnalysisServer {
|
|||
*
|
||||
* Return the set of fixes that are available for the errors at a given offset in a given file.
|
||||
*
|
||||
* If a request is made for a file which does not exist, or which is not currently subject to
|
||||
* analysis (e.g. because it is not associated with any analysis root specified to
|
||||
* analysis.setAnalysisRoots), an error of type GET_FIXES_INVALID_FILE will be generated.
|
||||
*
|
||||
* @param file The file containing the errors for which fixes are being requested.
|
||||
* @param offset The offset used to select the errors for which fixes will be returned.
|
||||
*/
|
||||
|
|
|
@ -76,6 +76,12 @@ public class RequestErrorCode {
|
|||
*/
|
||||
public static final String GET_ERRORS_INVALID_FILE = "GET_ERRORS_INVALID_FILE";
|
||||
|
||||
/**
|
||||
* An "edit.getFixes" request specified a FilePath which does not match a file currently subject to
|
||||
* analysis.
|
||||
*/
|
||||
public static final String GET_FIXES_INVALID_FILE = "GET_FIXES_INVALID_FILE";
|
||||
|
||||
/**
|
||||
* An "analysis.getImportedElements" request specified a FilePath that does not match a file
|
||||
* currently subject to analysis.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<body>
|
||||
<h1>Analysis Server API Specification</h1>
|
||||
<h1 style="color:#999999">Version
|
||||
<version>1.29.0</version>
|
||||
<version>1.29.1</version>
|
||||
</h1>
|
||||
<p>
|
||||
This document contains a specification of the API provided by the
|
||||
|
@ -2345,6 +2345,13 @@
|
|||
Return the set of fixes that are available for the errors at
|
||||
a given offset in a given file.
|
||||
</p>
|
||||
<p>
|
||||
If a request is made for a file which does not exist, or
|
||||
which is not currently subject to analysis (e.g. because it
|
||||
is not associated with any analysis root specified to
|
||||
analysis.setAnalysisRoots), an error of type
|
||||
<tt>GET_FIXES_INVALID_FILE</tt> will be generated.
|
||||
</p>
|
||||
<params>
|
||||
<field name="file">
|
||||
<ref>FilePath</ref>
|
||||
|
@ -5003,6 +5010,14 @@
|
|||
analysis.
|
||||
</p>
|
||||
</value>
|
||||
<value>
|
||||
<code>GET_FIXES_INVALID_FILE</code>
|
||||
<p>
|
||||
An "edit.getFixes" request specified a FilePath
|
||||
which does not match a file currently subject to
|
||||
analysis.
|
||||
</p>
|
||||
</value>
|
||||
<value>
|
||||
<code>GET_IMPORTED_ELEMENTS_INVALID_FILE</code>
|
||||
<p>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// To regenerate the file, use the script
|
||||
// "pkg/analysis_server/tool/spec/generate_files".
|
||||
|
||||
const String PROTOCOL_VERSION = '1.29.0';
|
||||
const String PROTOCOL_VERSION = '1.29.1';
|
||||
|
||||
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
|
||||
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';
|
||||
|
|
|
@ -17810,6 +17810,7 @@ class RequestError implements HasToJson {
|
|||
/// FORMAT_INVALID_FILE
|
||||
/// FORMAT_WITH_ERRORS
|
||||
/// GET_ERRORS_INVALID_FILE
|
||||
/// GET_FIXES_INVALID_FILE
|
||||
/// GET_IMPORTED_ELEMENTS_INVALID_FILE
|
||||
/// GET_KYTHE_ENTRIES_INVALID_FILE
|
||||
/// GET_NAVIGATION_INVALID_FILE
|
||||
|
@ -17891,6 +17892,11 @@ class RequestErrorCode implements Enum {
|
|||
static const RequestErrorCode GET_ERRORS_INVALID_FILE =
|
||||
RequestErrorCode._('GET_ERRORS_INVALID_FILE');
|
||||
|
||||
/// An "edit.getFixes" request specified a FilePath which does not match a
|
||||
/// file currently subject to analysis.
|
||||
static const RequestErrorCode GET_FIXES_INVALID_FILE =
|
||||
RequestErrorCode._('GET_FIXES_INVALID_FILE');
|
||||
|
||||
/// An "analysis.getImportedElements" request specified a FilePath that does
|
||||
/// not match a file currently subject to analysis.
|
||||
static const RequestErrorCode GET_IMPORTED_ELEMENTS_INVALID_FILE =
|
||||
|
@ -18022,6 +18028,7 @@ class RequestErrorCode implements Enum {
|
|||
FORMAT_INVALID_FILE,
|
||||
FORMAT_WITH_ERRORS,
|
||||
GET_ERRORS_INVALID_FILE,
|
||||
GET_FIXES_INVALID_FILE,
|
||||
GET_IMPORTED_ELEMENTS_INVALID_FILE,
|
||||
GET_KYTHE_ENTRIES_INVALID_FILE,
|
||||
GET_NAVIGATION_INVALID_FILE,
|
||||
|
@ -18076,6 +18083,8 @@ class RequestErrorCode implements Enum {
|
|||
return FORMAT_WITH_ERRORS;
|
||||
case 'GET_ERRORS_INVALID_FILE':
|
||||
return GET_ERRORS_INVALID_FILE;
|
||||
case 'GET_FIXES_INVALID_FILE':
|
||||
return GET_FIXES_INVALID_FILE;
|
||||
case 'GET_IMPORTED_ELEMENTS_INVALID_FILE':
|
||||
return GET_IMPORTED_ELEMENTS_INVALID_FILE;
|
||||
case 'GET_KYTHE_ENTRIES_INVALID_FILE':
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>Common Types</h1>
|
||||
<version>1.2.0</version>
|
||||
<version>1.2.1</version>
|
||||
<p>
|
||||
This document contains a specification of the types that are common between
|
||||
the analysis server wire protocol and the analysis server plugin wire
|
||||
|
|
Loading…
Reference in a new issue