-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IJ-CR-131092 the first step in Dart macro support: introduce DartAnal…
…ysisServerService.lspMessage_dart_textDocumentContent() close #903 (cherry picked from commit 1c825c586c0197369497d129a0040c2eeb7b9ddc) GitOrigin-RevId: ef50e62cad6e50daf55b483088cf79b8c6b1cf8d
- Loading branch information
1 parent
588ffe7
commit fcb67f7
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...irdPartySrc/analysisServer/com/google/dart/server/DartLspTextDocumentContentConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2024, the Dart project authors. | ||
* | ||
* Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.google.dart.server; | ||
|
||
import org.dartlang.analysis.server.protocol.RequestError; | ||
|
||
public interface DartLspTextDocumentContentConsumer extends Consumer { | ||
|
||
public void computedDocumentContents(String contents); | ||
|
||
/** | ||
* If the file contents can't be sent back, some {@link RequestError} is passed back instead. | ||
* | ||
* @param requestError the reason why a result was not passed back | ||
*/ | ||
public void onError(RequestError requestError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...com/google/dart/server/internal/remote/processor/DartLspTextDocumentContentProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2024, the Dart project authors. | ||
* | ||
* Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.google.dart.server.internal.remote.processor; | ||
|
||
import com.google.dart.server.DartLspTextDocumentContentConsumer; | ||
import com.google.gson.JsonObject; | ||
|
||
import org.dartlang.analysis.server.protocol.RequestError; | ||
|
||
/** | ||
* Instances of {@code DartLspTextDocumentContentProcessor} translate JSON result objects for a given | ||
* {@link LSPDartTextDocumentContentConsumer}. | ||
* | ||
* @coverage dart.server.remote | ||
*/ | ||
public class DartLspTextDocumentContentProcessor extends ResultProcessor { | ||
|
||
private final DartLspTextDocumentContentConsumer consumer; | ||
|
||
public DartLspTextDocumentContentProcessor(DartLspTextDocumentContentConsumer consumer) { | ||
this.consumer = consumer; | ||
} | ||
|
||
public void process(JsonObject resultObject, RequestError requestError) { | ||
if (resultObject != null) { | ||
// Example: {"lspResponse":{"id":"1","jsonrpc":"2.0","result":{"content":"file contents"}}} | ||
JsonObject lspResponse = resultObject.getAsJsonObject("lspResponse"); | ||
JsonObject innerResultObject = lspResponse.getAsJsonObject("result"); | ||
final String contents = innerResultObject.get("content").getAsString(); | ||
consumer.computedDocumentContents(contents); | ||
} | ||
if (requestError != null) { | ||
consumer.onError(requestError); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters