简体   繁体   English

Eclipse HTML5项目-JavaScript代码辅助仅在某些情况下有效

[英]Eclipse HTML5 Project - JavaScript Code Assist Only Works In Certain Cases

I am using Eclipse Juno developing a static web project. 我正在使用Eclipse Juno开发静态Web项目。 My project uses several different JavaScript files. 我的项目使用了几个不同的JavaScript文件。 One of the files contains a function: 其中一个文件包含一个功能:

function IconData(size, url) {
    this.size = size;
    this.url = url;
}

I have another function that returns an object of type IconData: 我还有另一个函数可以返回IconData类型的对象:

function PageInfo() {
    this.iconData = function() {
        var iconData = new IconData();
        iconData.size = 10;
        iconData.url = "http://somepage.com/image.png";
        return iconData;
    }
}

In another JavaScript file I create an instance of PageInfo and call the function iconData: 在另一个JavaScript文件中,我创建一个PageInfo实例,并调用函数iconData:

var page = new PageInfo();
// populate stuff
var icon = page.iconData();

If I type icon. 如果我键入图标。 then CTRL+SPACE to start code assist I get the following message popups in Eclipse: 然后按CTRL + SPACE来启动代码帮助,我在Eclipse中得到以下消息弹出窗口:

No Default Proposals 没有默认提案

没有默认提案

No Template Proposals 没有模板提案

没有模板提案

However, if I create a new instance of icon data such as: 但是,如果我创建一个图标数据的新实例,例如:

var iconData = new IconData();

then I type iconData. 然后我输入iconData。 then CTRL-SPACE the code assist pops up and show me all the possibilities: 然后CTRL-SPACE弹出代码帮助,并向我展示所有可能性:

代码协助工作

My question is, why doesn't code assist work in the first scenario but it works in the second? 我的问题是,为什么代码在第一种情况下不起作用而在第二种情况下起作用?

Thank you. 谢谢。

PS I have Google how to enable code assist for JavaScript in Eclipse I found several sites that said I need to make sure I have JavaScript Development Tools installed and I made sure that I have them installed so I know that is not the issue. PS我有Google如何在Eclipse中启用JavaScript的代码辅助功能。我找到了几个站点,说我需要确保已安装JavaScript开发工具,并确保已安装它们,所以我知道这不是问题。

I think it's a limitation with JSDT. 我认为这是JSDT的局限性。 I suggest you that you install tern.java which extends JSDT to improve JS completion, hyperlink, hover. 我建议您安装tern.java ,它扩展了JSDT以改善JS的完成度,超链接和悬停。

Copy your JS files in a folder, convert your project as tern and configure Script path with your folder. 将您的JS文件复制到一个文件夹中,将项目转换为tern并使用该文件夹配置脚本路径 Please read Getting Started to know how to do that. 请阅读入门,以了解如何进行操作。

Here a screenshot with your case (here scripts folder is configured as script path): 以下是您的案例的屏幕截图(此处scripts文件夹配置为脚本路径):

用tern.java完成

Please note that tern.java is developed with Eclipse Luna, so I suggest you to use this version and not Juno. 请注意,tern.java是使用Eclipse Luna开发的,因此建议您使用此版本而不是Juno。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM