|
| 1 | +package ts.core.tests; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.IOException; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import ts.TypeScriptException; |
| 8 | +import ts.client.ITypeScriptServiceClient; |
| 9 | +import ts.client.TypeScriptServiceClient; |
| 10 | +import ts.client.completions.ICompletionEntry; |
| 11 | +import ts.client.completions.ICompletionInfo; |
| 12 | +import ts.client.definition.DefinitionsInfo; |
| 13 | +import ts.client.navbar.ITypeScriptNavBarCollector; |
| 14 | +import ts.client.navbar.NavigationBarItem; |
| 15 | +import ts.utils.FileUtils; |
| 16 | + |
| 17 | +public class NavBarTest { |
| 18 | + |
| 19 | + public static void main(String[] args) throws InterruptedException, TypeScriptException, IOException { |
| 20 | + |
| 21 | + File projectDir = new File("./samples"); |
| 22 | + // sample2.ts has the following content: |
| 23 | + // var s = "";s. |
| 24 | + File sampleFile = new File(projectDir, "vscode.d.ts"); |
| 25 | + final String fileName = FileUtils.getPath(sampleFile); |
| 26 | + |
| 27 | + // Create TypeScript client |
| 28 | + final ITypeScriptServiceClient client = new TypeScriptServiceClient(projectDir, |
| 29 | + new File("../ts.repository/node_modules/typescript/bin/tsserver"), null); |
| 30 | + |
| 31 | + // Open "sample2.ts" in an editor |
| 32 | + Thread t1 = new Thread(new Runnable() { |
| 33 | + |
| 34 | + @Override |
| 35 | + public void run() { |
| 36 | + try { |
| 37 | + client.openFile(fileName, null); |
| 38 | + } catch (TypeScriptException e) { |
| 39 | + // TODO Auto-generated catch block |
| 40 | + e.printStackTrace(); |
| 41 | + } |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + Thread t2 = new Thread(new Runnable() { |
| 46 | + |
| 47 | + @Override |
| 48 | + public void run() { |
| 49 | + try { |
| 50 | + client.navbar(fileName, new ITypeScriptNavBarCollector() { |
| 51 | + |
| 52 | + @Override |
| 53 | + public void setNavBar(List<NavigationBarItem> items) { |
| 54 | + System.err.println(items); |
| 55 | + } |
| 56 | + }); |
| 57 | + } catch (TypeScriptException e) { |
| 58 | + // TODO Auto-generated catch block |
| 59 | + e.printStackTrace(); |
| 60 | + } |
| 61 | + } |
| 62 | + }); |
| 63 | + |
| 64 | + t1.start(); |
| 65 | + t2.start(); |
| 66 | + // client.join(); |
| 67 | + //client.dispose(); |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + private static void display(DefinitionsInfo definitionInfo) { |
| 72 | + // TODO Auto-generated method stub |
| 73 | + |
| 74 | + } |
| 75 | + |
| 76 | + private static void display(ICompletionInfo completionInfo) { |
| 77 | + System.out.println("getCompletionsAtLineOffset:"); |
| 78 | + ICompletionEntry[] entries = completionInfo.getEntries(); |
| 79 | + for (ICompletionEntry entry : entries) { |
| 80 | + System.out.println(entry.getName()); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments