-
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.
First Dart macro change, addition of the (unused) DartAnalysisServerS…
…ervice.lspMessage_dart_textDocumentContent(..) With the associated consumer and processor patterns for communication with the Dart SDK (Dart Analysis Server)
- Loading branch information
Showing
5 changed files
with
154 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
16 changes: 16 additions & 0 deletions
16
...irdPartySrc/analysisServer/com/google/dart/server/LSPDartTextDocumentContentConsumer.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,16 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package com.google.dart.server; | ||
|
||
import org.dartlang.analysis.server.protocol.RequestError; | ||
|
||
public interface LSPDartTextDocumentContentConsumer 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/LSPDartTextDocumentContentProcessor.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.LSPDartTextDocumentContentConsumer; | ||
import com.google.gson.JsonObject; | ||
|
||
import org.dartlang.analysis.server.protocol.RequestError; | ||
|
||
/** | ||
* Instances of {@code LSPDartTextDocumentContentProcessor} translate JSON result objects for a given | ||
* {@link LSPDartTextDocumentContentConsumer}. | ||
* | ||
* @coverage dart.server.remote | ||
*/ | ||
public class LSPDartTextDocumentContentProcessor extends ResultProcessor { | ||
|
||
private final LSPDartTextDocumentContentConsumer consumer; | ||
|
||
public LSPDartTextDocumentContentProcessor(LSPDartTextDocumentContentConsumer 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