Java Code Examples for org.eclipse.lsp4j.TextDocumentItem#getText()

The following examples show how to use org.eclipse.lsp4j.TextDocumentItem#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserFileHelperUtil.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
public String getLine(TextDocumentItem textDocumentItem, int line) {
	String text = textDocumentItem.getText();
	String[] lines = text.split("\\r?\\n", line + 2);
	if (lines.length >= line + 1) {
		return lines[line];
	}
	return null;
}
 
Example 2
Source File: TextDocument.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public TextDocument(TextDocumentItem document) {
	this(document.getText(), document.getUri());
	super.setVersion(document.getVersion());
	super.setLanguageId(document.getLanguageId());
}
 
Example 3
Source File: ParserFileHelperFactory.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
protected boolean containsCamelKafkaConnectPropertyKey(TextDocumentItem textDocumentItem) {
	String text = textDocumentItem.getText();
	return text.contains(CamelKafkaUtil.CAMEL_SINK_URL)
			|| text.contains(CamelKafkaUtil.CAMEL_SOURCE_URL);
}
 
Example 4
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
/**
 * Called whan a file is opened for editing in Visual Studio Code. We store
 * the file's contents in a String since any changes that have been made to
 * it may not have been saved yet. This method will not be called again if
 * the user simply switches to a different tab for another file and then
 * switched back to this one, without every closing it completely. In
 * other words, the language server does not usually know which file is
 * currently visible to the user in VSCode.
 */
@Override
public void didOpen(DidOpenTextDocumentParams params)
{
    TextDocumentItem textDocument = params.getTextDocument();
    String textDocumentUri = textDocument.getUri();
    if (!textDocumentUri.endsWith(FILE_EXTENSION_AS)
            && !textDocumentUri.endsWith(FILE_EXTENSION_MXML))
    {
        //code intelligence is available only in .as and .mxml files
        //so we ignore other file extensions
        return;
    }
    Path path = LanguageServerCompilerUtils.getPathFromLanguageServerURI(textDocumentUri);
    if (path == null)
    {
        return;
    }

    //even if it's not in a workspace folder right now, store it just in
    //case we need it later.
    //example: if we modify to source-path compiler option
    String text = textDocument.getText();
    fileTracker.openFile(path, text);

    WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderDataForSourceFile(path);
    if (folderData == null)
    {
        return;
    }

    if (fallbackConfig != null && folderData.equals(workspaceFolderManager.getFallbackFolderData()))
    {
        fallbackConfig.didOpen(path);
    }

    getProject(folderData);
    ILspProject project = folderData.project;
    if (project == null)
    {
        //something went wrong while creating the project
        return;
    }

    //notify the workspace that it should read the file from memory
    //instead of loading from the file system
    String normalizedPath = FilenameNormalization.normalize(path.toAbsolutePath().toString());
    IFileSpecification fileSpec = fileTracker.getFileSpecification(normalizedPath);
    compilerWorkspace.fileChanged(fileSpec);

    //if it's an included file, switch to the parent file
    IncludeFileData includeFileData = folderData.includedFiles.get(path.toString());
    if (includeFileData != null)
    {
        path = Paths.get(includeFileData.parentPath);
    }

    checkProjectForProblems(folderData);
}