Skip to content

Commit

Permalink
fix invalid range in VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
ydaveluy committed Apr 6, 2024
1 parent a4db46b commit 6e54730
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.xsmp.ide.symbol.XsmpDocumentSymbolDetailsProvider;
import org.eclipse.xsmp.ide.symbol.XsmpDocumentSymbolKindProvider;
import org.eclipse.xsmp.ide.symbol.XsmpDocumentSymbolNameProvider;
import org.eclipse.xsmp.ide.symbol.XsmpDocumentSymbolRangeProvider;
import org.eclipse.xsmp.ide.symbol.XsmpHierarchicalDocumentSymbolService;
import org.eclipse.xsmp.ide.workspace.XsmpProjectConfigProvider;
import org.eclipse.xtext.generator.GeneratorDelegate;
Expand All @@ -42,6 +43,7 @@
import org.eclipse.xtext.ide.server.symbol.DocumentSymbolMapper.DocumentSymbolDetailsProvider;
import org.eclipse.xtext.ide.server.symbol.DocumentSymbolMapper.DocumentSymbolKindProvider;
import org.eclipse.xtext.ide.server.symbol.DocumentSymbolMapper.DocumentSymbolNameProvider;
import org.eclipse.xtext.ide.server.symbol.DocumentSymbolMapper.DocumentSymbolRangeProvider;
import org.eclipse.xtext.ide.server.symbol.HierarchicalDocumentSymbolService;
import org.eclipse.xtext.workspace.IProjectConfigProvider;

Expand Down Expand Up @@ -136,4 +138,9 @@ public class XsmpcatIdeModule extends AbstractXsmpcatIdeModule
{
return XsmpDocumentSymbolDetailsProvider.class;
}

public Class< ? extends DocumentSymbolRangeProvider> bindDocumentSymbolRangeProvider()
{
return XsmpDocumentSymbolRangeProvider.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.NAMESPACE;
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.OPERATION;
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.PARAMETER;
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.PRIMITIVE_TYPE;
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.PROFILE;
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.PROFILE_REFERENCE;
import static org.eclipse.xsmp.model.xsmp.XsmpPackage.PROJECT;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected SymbolKind getSymbolKind(EClass clazz)
case ENTRY_POINT, ASSOCIATION -> SymbolKind.Object;
case OPERATION -> SymbolKind.Method;
case INTERFACE -> SymbolKind.Interface;
case FLOAT, INTEGER -> SymbolKind.Number;
case FLOAT, INTEGER, PRIMITIVE_TYPE -> SymbolKind.Number;
case CATALOGUE, PROJECT, TOOL, PROFILE -> SymbolKind.File;
case PROPERTY -> SymbolKind.Property;
case PARAMETER -> SymbolKind.Variable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (C) 2024 THALES ALENIA SPACE FRANCE.
*
* All rights reserved. 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
******************************************************************************/
package org.eclipse.xsmp.ide.symbol;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.util.Ranges;
import org.eclipse.xtext.ide.server.symbol.DocumentSymbolMapper.DocumentSymbolRangeProvider;

public class XsmpDocumentSymbolRangeProvider extends DocumentSymbolRangeProvider
{

@Override
public Range getSelectionRange(EObject object)
{
final var range = getRange(object);
if (range == null)
{
return null;
}
final var selectionRange = super.getSelectionRange(object);
// sometimes during edition the selection range is invalid and is outside the range.
// in this case return null to avoid error in vs code
return selectionRange != null && Ranges.containsRange(range, selectionRange) ? selectionRange
: null;
}
}

0 comments on commit 6e54730

Please sign in to comment.