forked from ThalesGroup/xsmp-modeler-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cyrilvrousos-tas/22-provide-language-serve…
…r-protocol 22 provide language server protocol
- Loading branch information
Showing
6 changed files
with
421 additions
and
2 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
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
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
53 changes: 53 additions & 0 deletions
53
org.eclipse.xsmp.ide/src/org/eclipse/xsmp/ide/hover/XsmpcatHoverService.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,53 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2023 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.hover; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.xtext.Keyword; | ||
import org.eclipse.xtext.ide.server.Document; | ||
import org.eclipse.xtext.ide.server.hover.HoverContext; | ||
import org.eclipse.xtext.ide.server.hover.HoverService; | ||
import org.eclipse.xtext.resource.XtextResource; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class XsmpcatHoverService extends HoverService | ||
{ | ||
@Inject | ||
private XsmpcatKeywordHovers keywordHovers; | ||
|
||
@Inject | ||
private XsmpcatKeywordAtOffsetHelper keywordHelper; | ||
|
||
@Override | ||
public String getContents(EObject element) | ||
{ | ||
if (element instanceof Keyword) | ||
{ | ||
return keywordHovers.hoverText((Keyword) element); | ||
} | ||
return super.getContents(element); | ||
} | ||
|
||
@Override | ||
protected HoverContext createContext(Document document, XtextResource resource, int offset) | ||
{ | ||
// Looking for a keyword | ||
final var result = keywordHelper.resolveKeywordAt(resource, offset); | ||
if (result != null) | ||
{ | ||
return new HoverContext(document, resource, offset, result.getSecond(), result.getFirst()); | ||
} | ||
|
||
return super.createContext(document, resource, offset); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
org.eclipse.xsmp.ide/src/org/eclipse/xsmp/ide/hover/XsmpcatKeywordAtOffsetHelper.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,43 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2023 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.hover; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.xtext.Keyword; | ||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
import org.eclipse.xtext.resource.XtextResource; | ||
import org.eclipse.xtext.util.ITextRegion; | ||
import org.eclipse.xtext.util.Pair; | ||
import org.eclipse.xtext.util.TextRegion; | ||
import org.eclipse.xtext.util.Tuples; | ||
|
||
public class XsmpcatKeywordAtOffsetHelper | ||
{ | ||
public Pair<EObject, ITextRegion> resolveKeywordAt(XtextResource resource, int offset) | ||
{ | ||
final var parseResult = resource.getParseResult(); | ||
if (parseResult != null) | ||
{ | ||
var leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset); | ||
if (leaf != null && leaf.isHidden() && leaf.getOffset() == offset) | ||
{ | ||
leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1); | ||
} | ||
if (leaf != null && leaf.getGrammarElement() instanceof Keyword) | ||
{ | ||
final var keyword = (Keyword) leaf.getGrammarElement(); | ||
return Tuples.create((EObject) keyword, | ||
(ITextRegion) new TextRegion(leaf.getOffset(), leaf.getLength())); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.