Skip to content
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

Caret-T: Javascript autocomplete #26

Closed
postacik opened this issue Apr 7, 2015 · 12 comments
Closed

Caret-T: Javascript autocomplete #26

postacik opened this issue Apr 7, 2015 · 12 comments
Labels

Comments

@postacik
Copy link

postacik commented Apr 7, 2015

Suppose I have file (a.js) with my functions in it.

In file b.js I write code which uses functions in a.js.

Can autocomplete give information about functions in a.js while working in b.js?

@Sevin777
Copy link
Owner

Sevin777 commented Apr 7, 2015

This is very similar to https://github.com/sevin7676/Ace.Tern/issues/18

This specific Tern extension has a quick hack to enable using the Reference Path tag supported by Visual Studio intellisense (also used by Type Script).

You can use this syntax as follows: (must be at top of file, multiple lines allowed)

/// <reference path="../a.js" />
/// <reference path="https://code.jquery.com/jquery-2.1.3.js" />

Also, the reference paths are not checked or updated until you call: editor.ternServer.docChanged(editor)

This method is a quick hack that is poorly implemented because I'm just using it for something specific. However, Tern supports adding other files for reference by configuring the RequireJS plugin or Node plugin. Example for rqeuireJS:

enableTern accepts boolean or configuration options

 var editor = ace.edit("editor");
 ace.config.loadModule('ace/ext/language_tools', function() {
     ace.config.loadModule('ace/ext/tern', function() {
         editor.setOptions({
             enableTern: {
                 plugins: {
                     requirejs: {
                         baseURL: '(set this)',
                         paths: '(optional)',
                         override: '(optional)',
                     },
                     doc_comment: {
                         fullDocs: true
                     }
                 }
             },
             enableSnippets: false,
             enableBasicAutocompletion: true,
         });
     });
 });

@postacik
Copy link
Author

postacik commented Apr 7, 2015

I'm using your Caret-T Chrome application and when I put the reference line at the top of a file, it has no effect on autocomplete.

///

Is this feature possible in Caret-T?

(I posted the question in this project because Caret-T about box points to this project for getting the source code instead of CaretTern project)

@Sevin777
Copy link
Owner

Sevin777 commented Apr 7, 2015

Yes it works in Caret-T. After you add the file reference to the top of the file switch to another tab, then switch back and it will reload the references.

Open Chrome's dev tools and look at the console as it logs info when it adds references including if it runs into an error:

image

success:

image

@Sevin777 Sevin777 changed the title Javascript autocomplete Caret-T: Javascript autocomplete Apr 7, 2015
@postacik
Copy link
Author

postacik commented Apr 7, 2015

I have the following lines in b.js

var goo = {
//stringProp
stringProp: "",
//mest property
numProp: 10
};

goo.stringProp = "str";
goo.numProp = 20;

And a.js looks like this:

image

When I type "goo." in a.js it does not display object goo's properties as they listed while working in b.js.

@Sevin777
Copy link
Owner

Sevin777 commented Apr 7, 2015

There is a bug that prevents local paths from working correctly unless they start with ../, and they must not be at the root. So it will work if your file is [root]/scripts/b.js and you use /// <reference path="../scripts/b.js" />

I haven't got around to fixing this bug yet.

@Sevin777 Sevin777 added the bug label Apr 7, 2015
@postacik
Copy link
Author

postacik commented Apr 7, 2015

Thanks, it works when library and projects files are in seperate folders under the same root.

@postacik postacik closed this as completed Apr 7, 2015
@postacik postacik reopened this Apr 7, 2015
@postacik
Copy link
Author

postacik commented Apr 7, 2015

Can you update the project source code to include library files in demo.html file as you explain in your first answer to this issue?

@Sevin777
Copy link
Owner

Sevin777 commented Apr 7, 2015

I'm not sure what you referring to: include library files in demo.html

@postacik
Copy link
Author

postacik commented Apr 7, 2015

I mean adding external js files for autocomplete with the following code change:

image

@postacik
Copy link
Author

postacik commented Apr 8, 2015

In ext-tern.js the following line exists in function loadExplicitVsRefs:

editor.ternServer.addDoc(path.replace(/^.*[\\\/]/, ''), xhr.responseText);

Can I add my js libraries to be used in autocomplete using this function?

@Sevin777
Copy link
Owner

Sevin777 commented Apr 8, 2015

Thats the code that automatically reads the /// <reference path="" /> comments.

You can also use: editor.ternServer.addDoc(fileName,fileContents) to manually add your source. https://github.com/sevin7676/Ace.Tern/blob/2d814fb4d2d68d0b4a765b6fcd07f96f8aaeb98f/ace-builds/src-noconflict/ext-tern.js#L425.

The demo has now been updated with better comments: https://github.com/sevin7676/Ace.Tern/blob/master/demo.html#L108

@Sevin777 Sevin777 closed this as completed Apr 8, 2015
@postacik
Copy link
Author

postacik commented Apr 8, 2015

Thank you very much. The following instruction does what I need.

editor.ternServer.addDoc(fileName,fileContents)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants