mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Revert "Bug 566093 - CDT LSP: null-free functions to retrieve URL from IDocument"
This reverts commit 46a799d96d
.
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
46a799d96d
commit
7cccb6ba3a
6 changed files with 13 additions and 116 deletions
|
@ -10,8 +10,5 @@ Require-Bundle: com.google.gson;bundle-version="2.8.2",
|
|||
org.junit,
|
||||
org.eclipse.lsp4j,
|
||||
org.eclipse.lsp4j.jsonrpc,
|
||||
org.eclipse.text;bundle-version="3.10.0",
|
||||
org.eclipse.lsp4e,
|
||||
org.eclipse.cdt.lsp.core,
|
||||
org.eclipse.core.filebuffers;bundle-version="3.6.0",
|
||||
org.eclipse.core.runtime;bundle-version="3.19.0"
|
||||
org.eclipse.cdt.lsp.core
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov (ArSysOp) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.lsp.text.tests;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.cdt.lsp.internal.text.DocumentUri;
|
||||
import org.eclipse.core.filebuffers.FileBuffers;
|
||||
import org.eclipse.core.filebuffers.LocationKind;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DocumentUriTest {
|
||||
|
||||
private final DocumentUri uri;
|
||||
|
||||
public DocumentUriTest() {
|
||||
uri = new DocumentUri();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyDocument() {
|
||||
assertTrue(uri.apply(new Document()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalDocument() {
|
||||
Document document = new Document();
|
||||
FileBuffers.createTextFileBufferManager().createEmptyDocument(new Path("some.c"), LocationKind.LOCATION);
|
||||
assertTrue(uri.apply(document).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workspaceDocument() {
|
||||
Document document = new Document();
|
||||
FileBuffers.createTextFileBufferManager().createEmptyDocument(new Path("some.c"), LocationKind.LOCATION);
|
||||
//it's a pity! see https://bugs.eclipse.org/bugs/show_bug.cgi?id=566044
|
||||
assertTrue(uri.apply(document).isEmpty());
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,6 @@ Export-Package: org.eclipse.cdt.cquery;x-friends:="org.eclipse.cdt.lsp.ui",
|
|||
org.eclipse.cdt.internal.cquery.core;x-internal:=true,
|
||||
org.eclipse.cdt.internal.cquery.ui;x-internal:=true,
|
||||
org.eclipse.cdt.lsp.core;x-friends:="org.eclipse.cdt.lsp.ui",
|
||||
org.eclipse.cdt.lsp.internal.core;x-internal:=true,
|
||||
org.eclipse.cdt.lsp.internal.text;x-friends:="org.eclipse.cdt.lsp.ui"
|
||||
org.eclipse.cdt.lsp.internal.core;x-internal:=true
|
||||
Bundle-Activator: org.eclipse.cdt.lsp.core.Activator
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -40,7 +39,6 @@ import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
|
|||
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
|
||||
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.TokenStore;
|
||||
import org.eclipse.cdt.lsp.internal.text.DocumentUri;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.ILanguageUI;
|
||||
import org.eclipse.cdt.ui.text.AbstractCScanner;
|
||||
|
@ -74,8 +72,6 @@ import org.eclipse.ui.editors.text.TextEditor;
|
|||
*/
|
||||
public class PresentationReconcilerCPP extends CPresentationReconciler {
|
||||
|
||||
private final DocumentUri documentUri;
|
||||
|
||||
private CCommentScanner fSinglelineCommentScanner;
|
||||
private CCommentScanner fMultilineCommentScanner;
|
||||
private SingleTokenCScanner fStringScanner;
|
||||
|
@ -130,7 +126,6 @@ public class PresentationReconcilerCPP extends CPresentationReconciler {
|
|||
}
|
||||
|
||||
public PresentationReconcilerCPP() {
|
||||
this.documentUri = new DocumentUri();
|
||||
fStringScanner = new SingleTokenCScanner(getTokenStoreFactory(), ICColorConstants.C_STRING);
|
||||
fMultilineCommentScanner = new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
fSinglelineCommentScanner = new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
|
@ -185,8 +180,9 @@ public class PresentationReconcilerCPP extends CPresentationReconciler {
|
|||
TextPresentation presentation = super.createPresentation(damage, document);
|
||||
|
||||
IDocument doc = textViewer.getDocument();
|
||||
Optional<URI> uri = documentUri.apply(doc);
|
||||
if (!uri.isPresent()) {
|
||||
URI uri = Server2ClientProtocolExtension.getUri(doc);
|
||||
|
||||
if (uri == null) {
|
||||
return presentation;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.eclipse.cdt.lsp.core;
|
|||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.cdt.cquery.CqueryInactiveRegions;
|
||||
import org.eclipse.cdt.cquery.CquerySemanticHighlights;
|
||||
|
@ -28,7 +27,6 @@ import org.eclipse.cdt.internal.cquery.CqueryMessages;
|
|||
import org.eclipse.cdt.internal.cquery.ui.HighlightingNames;
|
||||
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
|
||||
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
|
||||
import org.eclipse.cdt.lsp.internal.text.DocumentUri;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -59,12 +57,6 @@ import org.eclipse.ui.internal.WorkbenchWindow;
|
|||
@SuppressWarnings("restriction")
|
||||
public class Server2ClientProtocolExtension extends LanguageClientImpl {
|
||||
|
||||
private final DocumentUri uri;
|
||||
|
||||
public Server2ClientProtocolExtension() {
|
||||
this.uri = new DocumentUri();
|
||||
}
|
||||
|
||||
@JsonNotification("$cquery/progress")
|
||||
public final void indexingProgress(IndexingProgressStats stats) {
|
||||
|
||||
|
@ -92,18 +84,18 @@ public class Server2ClientProtocolExtension extends LanguageClientImpl {
|
|||
public final void setInactiveRegions(CqueryInactiveRegions regions) {
|
||||
URI uriReceived = regions.getUri();
|
||||
List<Range> inactiveRegions = regions.getInactiveRegions();
|
||||
//FIXME: AF: extract the retrieval of this document to a separate method
|
||||
IDocument doc = null;
|
||||
|
||||
// To get the document for the received URI.
|
||||
for (PresentationReconcilerCPP eachReconciler : PresentationReconcilerCPP.presentationReconcilers) {
|
||||
IDocument currentReconcilerDoc = eachReconciler.getTextViewer().getDocument();
|
||||
Optional<URI> currentReconcilerUri = uri.apply(currentReconcilerDoc);
|
||||
URI currentReconcilerUri = getUri(currentReconcilerDoc);
|
||||
|
||||
if (currentReconcilerUri.isEmpty()) {
|
||||
if (currentReconcilerUri == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (uriReceived.equals(currentReconcilerUri.get())) {
|
||||
if (uriReceived.equals(currentReconcilerUri)) {
|
||||
doc = currentReconcilerDoc;
|
||||
break;
|
||||
}
|
||||
|
@ -146,17 +138,17 @@ public class Server2ClientProtocolExtension extends LanguageClientImpl {
|
|||
URI uriReceived = highlights.getUri();
|
||||
|
||||
// List of PresentationReconcilerCPP objects attached with same C++ source file.
|
||||
//FIXME: AF: extract the retrieval of this list to a separate method
|
||||
List<PresentationReconcilerCPP> matchingReconcilers = new ArrayList<>();
|
||||
|
||||
for (PresentationReconcilerCPP eachReconciler : PresentationReconcilerCPP.presentationReconcilers) {
|
||||
IDocument currentReconcilerDoc = eachReconciler.getTextViewer().getDocument();
|
||||
Optional<URI> currentReconcilerUri = uri.apply(currentReconcilerDoc);
|
||||
if (currentReconcilerUri.isEmpty()) {
|
||||
URI currentReconcilerUri = getUri(currentReconcilerDoc);
|
||||
|
||||
if (currentReconcilerUri == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (uriReceived.equals(currentReconcilerUri.get())) {
|
||||
if (uriReceived.equals(currentReconcilerUri)) {
|
||||
matchingReconcilers.add(eachReconciler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov (ArSysOp) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.lsp.internal.text;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.lsp4e.LSPEclipseUtils;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class DocumentUri implements Function<IDocument, Optional<URI>> {
|
||||
|
||||
@Override
|
||||
public Optional<URI> apply(IDocument document) {
|
||||
return Optional.ofNullable(document)//
|
||||
//FIXME rewrite involved static utilities and contribute the result back to LSP4E
|
||||
.flatMap(d -> Optional.ofNullable(LSPEclipseUtils.getFile(d)))
|
||||
.flatMap(f -> Optional.ofNullable(LSPEclipseUtils.toUri(f)));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue