2011-02-08 84 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,该文件是从未在资源视图中显示。它在操作系统的实际文件夹中仍然很明显,但我并不担心那个。