-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add completion for map group names
Add completion for map group names in `cfgeventgroups.xml`.
- Loading branch information
Showing
2 changed files
with
43 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
42 changes: 42 additions & 0 deletions
42
...ithub/rvost/lemminx/dayz/participants/completion/CfgEventGroupsCompletionParticipant.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,42 @@ | ||
package io.github.rvost.lemminx.dayz.participants.completion; | ||
|
||
import io.github.rvost.lemminx.dayz.DayzMissionService; | ||
import io.github.rvost.lemminx.dayz.model.CfgEventGroupsModel; | ||
import org.eclipse.lemminx.commons.BadLocationException; | ||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.services.extensions.completion.CompletionParticipantAdapter; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionRequest; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionResponse; | ||
import org.eclipse.lsp4j.CompletionItemKind; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
|
||
public class CfgEventGroupsCompletionParticipant extends CompletionParticipantAdapter { | ||
private final DayzMissionService missionService; | ||
|
||
public CfgEventGroupsCompletionParticipant(DayzMissionService missionService) { | ||
this.missionService = missionService; | ||
} | ||
|
||
@Override | ||
public void onAttributeValue(String valuePrefix, ICompletionRequest request, ICompletionResponse response, CancelChecker cancelChecker) throws Exception { | ||
var doc = request.getXMLDocument(); | ||
if (CfgEventGroupsModel.isCfgEventGroups(doc)) { | ||
computeMapGroupCompletion(request, response, doc); | ||
} | ||
} | ||
|
||
private void computeMapGroupCompletion(ICompletionRequest request, ICompletionResponse response, DOMDocument document) throws BadLocationException { | ||
var editRange = request.getReplaceRange(); | ||
var offset = document.offsetAt(editRange.getStart()); | ||
var node = document.findNodeAt(offset); | ||
var attr = node.findAttrAt(offset); | ||
|
||
if (CfgEventGroupsModel.TYPE_ATTRIBUTE.equals(attr.getName()) && | ||
!node.hasAttribute(CfgEventGroupsModel.SPAWNSECONDARY_ATTRIBUTE)) { | ||
var options = missionService.getMapGroups(); | ||
options.stream() | ||
.map(option -> CompletionUtils.toCompletionItem(option, request, editRange, CompletionItemKind.Class)) | ||
.forEach(response::addCompletionItem); | ||
} | ||
} | ||
} |