2011-02-08 52 views
1

我正在使用Helios。Eclipse插件:帶有非文件IEditorInput的JS編輯器

我們正在編寫一個包含FormEditor插件。在這個編輯器的其中一個選項卡中是嵌套的JS編輯器。在該JS編輯器中,我們希望我們的對象模型以自動完成模式顯示。

我已經想通了如何將JS自然和我們的庫添加到時自動我們的一個文件被打開當前項目的JS構建路徑(這種行爲可以被禁用)。

我們有JSDoc存根,a,IJsGlobalScopeContainerInitializerSystemLibraryLocation等等。

public class LibInitializer extends JsGlobalScopeContainerInitializer implements IJsGlobalScopeContainerInitializer { 
    //... 

    public int getKind() { 
    return IJsGlobalScopeContainer.K_SYSTEM; 
    } 

    public boolean canUpdateJsGlobalScopeContainer(IPath containerPath, IJavaScriptProject project) { 
    return true; 
    } 

    static class LibLocation extends SystemLibraryLocation { 
    //... 
    LibLocation() { 
     super(); 
    } 

    public char[][] getLibraryFileNames() { 
     // what's plural of "chars"? 
     return LibInitializer.LIBRARY_FILE_CHARSES; 
    } 

    public IPath getWorkingLibPath() { 
     // stash our libraries in our state location for Easy Access. 
     return WebFormsUIPlugin.getDefault().getStateLocation().append("jsLib"); //$NON-NLS-1$ 
    } 

當我們的JS編輯器被初始化時,代碼被調用。所有返回的路徑都顯示爲有效。

但我不能爲我的生命弄清楚爲什麼我們的對象不自動完成或JSDoc或任何東西出現。 JS編輯器的調試選項不是非常有用。日誌或控制檯輸出中沒有例外(我可以找到)。

如何確定我的庫文件是否正確解析?有沒有辦法轉儲所有可用的JS類?


編輯的更多細節:

的JS編輯器作用於ByteArrayStorageEditorInput(我們寫的),而不是通常的FileEditorInput。

在這個項目(JS性質和JS包括路徑是項目級別設置),如果我創建一個JS文件,所有的代碼完成信息是從包括路徑的任何和所有的圖書館,包括我們的存在。但在我們的編輯器中,我看到沒有代碼完成信息。不是從我們的圖書館。不是來自任何其他標準庫。甚至沒有「ECMAScript內置庫」。

所以它看起來像得到這個工作的唯一方法是使用一個文件。這也會讓問題標記在我們的編輯器中工作:沒有文件意味着問題標籤中沒有列出。

所以這看起來像一個IEditorInput問題,而不是一個JS庫的問題。

回答

0

看起來像我將不得不把我的腳本到一個文件中,並用它來獲得正常的行爲。

是的。這工作。我創建正是如此文件:

private FileEditorInput buildJSInput() throws CoreException { 
    FileEditorInput ourInput = (FileEditorInput)getEditorInput().getAdapter(FileEditorInput.class); 
    IFile ourFile = ourInput.getFile(); 
    // keep our temp file in the same directory as the DFD to avoid collisions 
    IContainer parent = ourFile.getParent(); 

    IPath tmpPath = new Path(ourFile.getName() + "_tmpServerSideJS.js"); //$NON-NLS-1$ 
    jsFile = parent.getFile(tmpPath); 

    byte jsBytes[] = model.getModel().getServerScript().getBytes(); 
    InputStream jsIn = new ByteArrayInputStream(jsBytes); 
    if (!jsFile.exists()) { 
     jsFile.create(jsIn, IResource.HIDDEN, null); 
    } else { 
     jsFile.setContents(jsIn, 0, null); 
    } 


    return new FileEditorInput(jsFile); 
} 

使用IResource.HIDDEN,該文件是從未在資源視圖中顯示。它在操作系統的實際文件夾中仍然很明顯,但我並不擔心那個。