-
Notifications
You must be signed in to change notification settings - Fork 415
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
Add imports folding support #555
Comments
@aeschli For this feature, is it about https://github.com/Microsoft/vscode-languageserver-protocol-foldingprovider? And is the API still in proposed or when will be finalized into the server spec? |
Yes, that's the one. No more changes to the protocol planed from my side. I try to get it added to the 'official' APIs soon, but no need to wait for that. |
Matching jdt.ls issue: eclipse-jdtls/eclipse.jdt.ls#694 |
Not sure if this is the right approach at all but here's a very basic example/POC of how this can be done: const IMPORT_STATEMENT_TEST: RegExp = /^import [^;]+;$/;
class ImportFoldingRangeProvider implements FoldingRangeProvider {
provideFoldingRanges(document: TextDocument): FoldingRange[] {
const position = { lineStart: null, lineEnd: null };
for (let lineNumber = 0; lineNumber < document.lineCount; lineNumber++) {
const lineText: TextLine = document.lineAt(lineNumber);
const isImportStatement = IMPORT_STATEMENT_TEST.test(lineText.text);
if (isImportStatement) {
if (position.lineStart === null) {
position.lineStart = lineNumber;
position.lineEnd = lineNumber;
} else {
position.lineEnd = lineNumber;
}
}
}
return [new FoldingRange(position.lineStart, position.lineEnd)];
}
}
function provideImportFolding() {
languages.registerFoldingRangeProvider({ scheme: 'file', language: 'java' }, new ImportFoldingRangeProvider());
} Screenshot: |
With server-side folding: Now we need VS Code to allow users to define the initial collapsing state of a region. I can imagine people needing to have the imports section collapsed by default. |
At least, the folding state is preserved when closing/reopening the files |
So a new preference is introduced: |
Note that you can achieve the same with setting in VSCode
|
@aeschli indeed. The |
Is there a way to "fold" by default in all files? |
@hgodoy not at the moment. Please vote for microsoft/vscode#40338 (comment) |
@fbricon Ok. Thanks! |
@fbricon looks like it is broken atm. Fails even on simple things, so i had to switch back. |
@justatestaccountfortdl please define "broken". Can you share a screencast, logs? |
Well, defining 'broken' in the context of having to switch back to regular indentation based strategy would sound like: it does not show up any foldings whenever i turn it on. Could you clarify, what kind of logs do you need and where can i get them from? A test sample: // Test java class.
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
public class Test implements A.B, C.D, E {
private native int start(String path, int value);
private native int write(ByteBuffer pBuffer, int iLen);
private native void stop();
private int bIsEnabled;
public Boolean isBuffering() {
if (bIsEnabled == -1) {
return null;
}
return bIsEnabled == 0 ? true : false;
}
} Switching back to indentation based (either through strategy (replaced auto to indentation) and by turning off 'smart folding range' (which is going to affect in the same way, since it will fall back to indentation)): https://pastie.io/rhemqo.cpp these logs? |
#667 i see, yet i was not using an android application project (at least on the sample screenshots). I tried to switch to pre-release mode but still. |
similar to typescript support (https://code.visualstudio.com/updates/v1_24#_import-folding)
The text was updated successfully, but these errors were encountered: