-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement file type defnition mapping #253
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.wso2.lsp4intellij.client.languageserver.serverdefinition; | ||
|
||
import org.wso2.lsp4intellij.client.connection.StreamConnectionProvider; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.net.Socket; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* TcpServerDefinition is a {@link LanguageServerDefinition} that connects to an LSP implementation over a TCP socket. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class TcpServerDefinition extends LanguageServerDefinition { | ||
private final TcpStreamConnectionProvider connectionProvider; | ||
|
||
/** | ||
* Creates a new TcpServerDefinition with no language IDs | ||
* | ||
* @param ext the extension this lsp definition is for | ||
* @param host the host of the language server | ||
* @param port the port of the language server | ||
*/ | ||
public TcpServerDefinition(String ext, String host, int port) { | ||
this(ext, host, port, Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Create a new TcpServerDefinition | ||
* | ||
* @param ext the extension this lsp definition is for | ||
* @param host the host of the language server | ||
* @param port the port of the language server | ||
* @param langIds The language server ids mapping to extension(s). | ||
*/ | ||
public TcpServerDefinition(String ext, String host, int port, Map<String, String> langIds) { | ||
this.languageIds = langIds; | ||
this.ext = ext; | ||
|
||
// We can do this upfront as we don't care about the working directory | ||
connectionProvider = new TcpStreamConnectionProvider(host, port); | ||
} | ||
|
||
@Override | ||
public StreamConnectionProvider createConnectionProvider(String workingDir) { | ||
return connectionProvider; | ||
} | ||
|
||
private static class TcpStreamConnectionProvider implements StreamConnectionProvider { | ||
private final String host; | ||
private final int port; | ||
|
||
private InputStream is; | ||
private OutputStream os; | ||
|
||
private Socket socket; | ||
|
||
private TcpStreamConnectionProvider(String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
|
||
@Override | ||
public void start() throws IOException { | ||
socket = new Socket(host, port); | ||
|
||
// Do this here as these methods can throw IO exception, which we don't want to handle that in the getters | ||
is = socket.getInputStream(); | ||
os = socket.getOutputStream(); | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() { | ||
return is; | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() { | ||
return os; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
try { | ||
socket.close(); | ||
} catch (IOException e) { | ||
// ignore... nothing we (anybody?) can do about this | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ | |
import org.eclipse.lsp4j.DiagnosticTag; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.wso2.lsp4intellij.IntellijLanguageClient; | ||
import org.wso2.lsp4intellij.client.languageserver.ServerStatus; | ||
import org.wso2.lsp4intellij.client.languageserver.wrapper.LanguageServerWrapper; | ||
import org.wso2.lsp4intellij.editor.EditorEventManager; | ||
|
@@ -67,7 +66,7 @@ public Object collectInformation(@NotNull PsiFile file, @NotNull Editor editor, | |
VirtualFile virtualFile = file.getVirtualFile(); | ||
|
||
// If the file is not supported, we skips the annotation by returning null. | ||
if (!FileUtils.isFileSupported(virtualFile) || !IntellijLanguageClient.isExtensionSupported(virtualFile)) { | ||
if (!FileUtils.isFileSupported(virtualFile) || !FileUtils.isFileSupported(virtualFile)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant checks |
||
return null; | ||
} | ||
EditorEventManager eventManager = EditorEventManagerBase.forEditor(editor); | ||
|
@@ -100,7 +99,7 @@ public void apply(@NotNull PsiFile file, Object annotationResult, @NotNull Annot | |
} | ||
|
||
VirtualFile virtualFile = file.getVirtualFile(); | ||
if (FileUtils.isFileSupported(virtualFile) && IntellijLanguageClient.isExtensionSupported(virtualFile)) { | ||
if (FileUtils.isFileSupported(virtualFile) && FileUtils.isFileSupported(virtualFile)) { | ||
String uri = FileUtils.VFSToURI(virtualFile); | ||
// TODO annotations are applied to a file / document not to an editor. so store them by file and not by editor.. | ||
EditorEventManager eventManager = EditorEventManagerBase.forUri(uri); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,27 +22,14 @@ | |
import com.intellij.openapi.editor.event.DocumentListener; | ||
import com.intellij.openapi.fileEditor.FileDocumentManager; | ||
import com.intellij.openapi.util.text.StringUtil; | ||
import org.eclipse.lsp4j.DidChangeTextDocumentParams; | ||
import org.eclipse.lsp4j.DidCloseTextDocumentParams; | ||
import org.eclipse.lsp4j.DidOpenTextDocumentParams; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent; | ||
import org.eclipse.lsp4j.TextDocumentIdentifier; | ||
import org.eclipse.lsp4j.TextDocumentItem; | ||
import org.eclipse.lsp4j.TextDocumentSyncKind; | ||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier; | ||
import org.wso2.lsp4intellij.client.languageserver.requestmanager.RequestManager; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.eclipse.lsp4j.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets avoid wildcard imports. |
||
import org.wso2.lsp4intellij.client.languageserver.wrapper.LanguageServerWrapper; | ||
import org.wso2.lsp4intellij.utils.ApplicationUtils; | ||
import org.wso2.lsp4intellij.utils.DocumentUtils; | ||
import org.wso2.lsp4intellij.utils.FileUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets avoid wildcard imports. |
||
|
||
public class DocumentEventManager { | ||
private final Document document; | ||
|
@@ -152,9 +139,10 @@ public void documentOpened() { | |
LOG.warn("trying to send open notification for document which was already opened!"); | ||
} else { | ||
openDocuments.add(document); | ||
final String extension = FileDocumentManager.getInstance().getFile(document).getExtension(); | ||
VirtualFile file = FileDocumentManager.getInstance().getFile(document); | ||
String languageId = wrapper.serverDefinition.languageIdFor(file); | ||
wrapper.getRequestManager().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(identifier.getUri(), | ||
wrapper.serverDefinition.languageIdFor(extension), | ||
languageId, | ||
++version, | ||
document.getText()))); | ||
} | ||
|
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.
I'm a bit new to this but it might be a safe assumption to assume that all file types are singletons and have this be