Skip to content

Commit

Permalink
Merge pull request #2 from cyrilvrousos-tas/22-provide-language-serve…
Browse files Browse the repository at this point in the history
…r-protocol

22 provide language server protocol
  • Loading branch information
cyrilvrousos-tas authored Jul 11, 2023
2 parents c9db497 + c25d715 commit eb57eda
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 2 deletions.
4 changes: 2 additions & 2 deletions org.eclipse.xsmp.ide/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.xsmp,
org.eclipse.xtext.ide,
org.eclipse.xtext.xbase.ide,
org.eclipse.lsp4j,
org.antlr.runtime;bundle-version="[3.2.0,3.2.1)",
org.eclipse.xsmp.lib;bundle-version="1.1.0";visibility:=reexport,
org.apache.log4j
org.apache.log4j;bundle-version="1.2.24",
org.eclipse.lsp4j;bundle-version="0.20.1"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.xsmp.ide,
org.eclipse.xsmp.ide.contentassist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@
package org.eclipse.xsmp.ide;

import org.eclipse.xsmp.ide.contentassist.XsmpcatIdeContentProposalProvider;
import org.eclipse.xsmp.ide.hover.XsmpcatHoverService;
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider;
import org.eclipse.xtext.ide.editor.quickfix.IQuickFixProvider;
import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2;
import org.eclipse.xtext.ide.server.codeActions.QuickFixCodeActionService;
import org.eclipse.xtext.ide.server.hover.HoverService;

/**
* Use this class to register ide components.
*/
public class XsmpcatIdeModule extends AbstractXsmpcatIdeModule
{
static
{
@SuppressWarnings("unused")
final Class< ? >[] classes = {
org.apache.log4j.ConsoleAppender.class,
org.apache.log4j.DailyRollingFileAppender.class,
org.apache.log4j.PatternLayout.class };
}

public Class< ? extends IQuickFixProvider> bindIQuickFixProvider()
{
return XsmpcatIdeQuickfixProvider.class;
Expand All @@ -35,4 +46,10 @@ public class XsmpcatIdeModule extends AbstractXsmpcatIdeModule
{
return XsmpcatIdeContentProposalProvider.class;
}

public Class< ? extends HoverService> bindHoverService()
{
return XsmpcatHoverService.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ class XsmpcatIdeContentProposalProvider extends AbstractIdeContentProposalProvid
def private String getCrossReferences(EObject eObject, EReference eReference) {
val scope = scopeProvider.getScope(eObject, eReference)
val filteredCandidates = Iterables.filter(scope.allElements, filter.getFilter(eObject, eReference))

if (filteredCandidates.empty) {
return "None"
}

return Joiner.on(",").join(filteredCandidates.map[it|it.name])
}
Expand Down
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);
}

}
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;
}
}
Loading

0 comments on commit eb57eda

Please sign in to comment.