-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize support for documentLink (see #56)
- Loading branch information
1 parent
84501fb
commit 3218682
Showing
4 changed files
with
104 additions
and
4 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
78 changes: 78 additions & 0 deletions
78
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLDocumentLink.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,78 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.services; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.lsp4j.DocumentLink; | ||
import org.eclipse.lsp4xml.commons.TextDocument; | ||
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry; | ||
|
||
/** | ||
* XML document link support. | ||
* | ||
*/ | ||
class XMLDocumentLink { | ||
|
||
private final XMLExtensionsRegistry extensionsRegistry; | ||
|
||
public XMLDocumentLink(XMLExtensionsRegistry extensionsRegistry) { | ||
this.extensionsRegistry = extensionsRegistry; | ||
} | ||
|
||
public List<DocumentLink> findDocumentLinks(TextDocument document) { | ||
List<DocumentLink> newLinks = new ArrayList<>(); | ||
// TODO: call extension | ||
/*let rootAbsoluteUrl: Uri | null = null; | ||
Scanner scanner = XMLScanner.createScanner(document.getText(), 0); | ||
TokenType token = scanner.scan(); | ||
let afterHrefOrSrc = false; | ||
let afterBase = false; | ||
let base: string | undefined = void 0; | ||
while (token != TokenType.EOS) { | ||
switch (token) { | ||
case TokenType.StartTag: | ||
if (!base) { | ||
let tagName = scanner.getTokenText().toLowerCase(); | ||
afterBase = tagName === 'base'; | ||
} | ||
break; | ||
case TokenType.AttributeName: | ||
let attributeName = scanner.getTokenText().toLowerCase(); | ||
afterHrefOrSrc = attributeName === 'src' || attributeName === 'href'; | ||
break; | ||
case TokenType.AttributeValue: | ||
if (afterHrefOrSrc) { | ||
let attributeValue = scanner.getTokenText(); | ||
if (!afterBase) { // don't highlight the base link itself | ||
let link = createLink(document, documentContext, attributeValue, scanner.getTokenOffset(), scanner.getTokenEnd(), base); | ||
if (link) { | ||
newLinks.push(link); | ||
} | ||
} | ||
if (afterBase && typeof base === 'undefined') { | ||
base = normalizeRef(attributeValue, document.languageId); | ||
if (base && documentContext) { | ||
base = documentContext.resolveReference(base, document.uri); | ||
} | ||
} | ||
afterBase = false; | ||
afterHrefOrSrc = false; | ||
} | ||
break; | ||
} | ||
token = scanner.scan(); | ||
}*/ | ||
return newLinks; | ||
} | ||
} |
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
3218682
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests?