sevin777 / ace.tern Goto Github PK
View Code? Open in Web Editor NEWTern plugin for Ace Editor
License: MIT License
Tern plugin for Ace Editor
License: MIT License
Fix this... it worked before
tern.switchToDoc called but not defined (need to specify this in options to enable jumpting between documents). name=/Code/Scripts/StandardScripts.js; start= Object {row: 6408, column: 9}
Clean this up and remove when done:
Ace keeps all the editor states (selection, scroll position, etc.) in editor.session, which is very useful for making a tabbed editor:
var EditSession = require("ace/edit_session").EditSession
var js = new EditSession("some js code")
var css = new EditSession(["some", "css", "code here"])
// and then to load document into editor, just call
editor.setSession(js)
IT APPEARS THAT CODEMIRROR.DOC AND ACE.EDITSESSION ARE THE SAME THING (OR CLOSE TO IT)
There is also ace.document: Contains the text of the document. Document can be attached to several EditSessions.--this is different from CM.Doc
CodeMirror.tern works by passing the CodeMirror instance to functions that require it, and the CodeMirror.Doc to functions that dont need the instance
- paralel: Ace should pass the editor instance to some functions, and the edit session to others
- NOTE: the codeMirror doc has a property 'cm' that contains the editor instance that is holding that doc...
but it doesnt appear to be used by the plugin
this would be the equivalent of adding the editor instance to the edit session (could do this if needed)
It should be cool if you can integrate https://github.com/angelozerr/tern-guess-types
If you need more informations about that, don't hesitate to tell me. Thanks!
/**
* @param {function} cb - callback to execute before setting value.
* Will only be executed if value is passed.
* 1st param {object} v - is new value.
* 2nd param {fn->bool} [same] - callback that returns bool indicating if new value is same as current
* 3rd param {object} [current] - the current value for this property
* Returns new value to use for setting value, or undefined to not set value.
*/
function test(cb) {}
When more than one {type}
string exists within a single parameter it messes up such that:
Need to change parsing to not replace all, but only replace the first. (but make sure that all get highlighted)
Hi,
Thanks you for your work...
I think the two line :
var pos = editor.getSelectionRange().end;
var tok = editor.session.getTokenAt(pos.row, pos.column);
have editor variable misspelled, on my local file I've changed by :
var pos = e.editor.getSelectionRange().end;
var tok = e.editor.session.getTokenAt(pos.row, pos.column);
it's work fine
have a good day
Sebastien
//automatically start auto complete when period is typed
var onAfterExec_Tern = function(e, commandManager) {
if (e.command.name === "insertstring" && e.args === ".") {
if (e.editor.ternServer && e.editor.ternServer.enabledAtCurrentLocation(e.editor)) {
var pos = e.editor.getSelectionRange().end;
var tok = e.editor.session.getTokenAt(pos.row, pos.column);
Hi @sevin7676 ,
thanks for working on Caret-T, I just found out (not by myself) that it supports inserting snippets, which I was looking for a lot (I'm on a chromebook).
I guess would be good to write about it in the features list on it's chrome store page, as many folks like me have no idea that "Tern" means snippets too.
Now my actual question: is it possible to define our own snippets, perhaps in some .json file, that the app will search too when offering suggestions when clicking on tab
?
Jump to definition not working in complex structures. Will get could not find definition when the same property will work with find references and show type. try Chart.js ~line 122 CT.c.init();
I'm not sure if this is possible or not, but is there a way to get Tern to analyse a particular JS file that I'm pulling in so that when I reference the objects from that file in my Ace edited script the available properties, functions, etc show up?
For example, say I'm loading a utility or API JS like D3 or JQuery or something like that. When I make use of that API in my Ace editor I only see autocomplete choices that are derived from what I've already done in my local JS (say if I have previously invoked function "a" I will see "a" show up as a suggestion). Is there some way to get it to go a step further with the analysis/search?
in TernServer:
editor.ternServer.addDoc(path.replace(/^.*[\\\/]/, ''), xhr.responseText);
remove the .replace....
after path as the popup that shows the source cleans the path
undo/redo operation only working for first tab... this must be fixed to fulfill the purpose of making tabs
allow configuring things like tern plugins for Caret-T using Caret's configuration (json page)
Or - modify Marijnh's code that reads tern-project file (for node) to work for web/chrome.
Determine how tern should function when multiple cursors are present
Cool project! Just wondering, are there any plans to support other languages, e.g. Java?
Marijnh changed the way that full doc requests are made in Tern. After upgrading to new Tern version code will need to be changed to support this:
ternjs/tern#425 (comment)
This code makes makes the editor think its in a function call when its not:
for (var i = 1; i < count.length; i++) {
count[i]
}
server.getCallPos(editor); //test
When is the right time to call the following function?
editor.ternServer.addDoc(fileName,fileContents)
Is there an event which tells that tern server is started?
I'm asking this because sometimes the fileContents I add using the addDoc function are not shown in autocomplete popup.
Here is where I call the function:
ace.config.loadModule('ace/ext/language_tools', function() {
ace.config.loadModule('ace/ext/tern', function() {
editor.setOptions({
enableTern: {
/* http://ternjs.net/doc/manual.html#option_defs */
defs: ['jquery', 'browser', 'ecma5'],
/* defs: ['jquery', 'ecma5'], */
/* http://ternjs.net/doc/manual.html#plugins */
plugins: {
doc_comment: {
fullDocs: true
}
},
useWorker: useWebWorker,
switchToDoc: function(name, start) {
console.log('switchToDoc called but not defined. name=' + name + '; start=', start);
},
startedCb: function() {
//once tern is enabled, it can be accessed via editor.ternServer
console.log('editor.ternServer:', editor.ternServer);
var library = _external.getLibrary();
console.log(library);
editor.ternServer.addDoc('mylib',library);
},
},
enableSnippets: false,
enableBasicAutocompletion: true,
});
});
});
Is there any way I can add variables and functions to the autocomplete which are not actually presented in the code editor?
Like I have this in the code editor:
function send(x, y) {
// Things are happening here
return true;
}
And what I would like to do is, I create some objects like:
var things = {
"hello": "world"
}
And I would like that if I start to type things. + ctrl+space into the editor, I get the hello as a hint.
Can we do something like this?
http://usejsdoc.org/tags-link.html
Right now it just parses out URLS and turns them into links. It should be able to parse out JSDoc link tags to create the text of the link (caption)
I think I broke it even worse while trying to fix within Caret. Try it on the tab demo to see if it works.
perhaps use grunt wit this plugin
After find references is called, auto focus on the first item in the select box so keys can be used instead of having to click in the box.
Can you please explain how the beautify extension you've included in the project works?
I could not find out how the following code helps to beautify the code.
ace.config.loadModule('ace/ext/html_beautify', function() {
editor.setOptions({
autoBeautify: true
});
});
Add a feature that generates a JS doc outline for an existing function
function test(a,b){
return a*b;
}
Should generate:
/**
* @returns {number} {description}
* @param {number} a - {description}
* @param {number b - {description}
*/
The result should use Ace's snippets feature (generate a dynamic snippet example). Each {description}
placeholder is part of the snippet. Use tern to infer type, and if type cant be inferred then make type part of the snippet;
There is already an existing extension for Brackets that does something like this, so check it out first.
add user configuration beautify options
ace.config.loadModule('ace/ext/html_beautify', function (beautify) {
editor.setOptions({
autoBeautify: true
});
//modify beautify options as needed:
beautifyOptions = {}//user options (will have to parse each)
});
Is it possible to add own methods or texts to be suggested?
Curious if this is up to date with the newest version of ACE? If not what version was this forked at?
I just got a new chromebook and was dismayed to see my favorite editor was missing from the chrome webstore, I hope it it temporary or else I will have to figure out how install it from github.
Keep up the good work
Aonghus
closing bracket shouldn't trigger auto format when its inside of a string literal (using string interpolation)
`string interpolation bug ${closeThisBraketAndItTriesToAutoFormat`
Interpolation is only allowed in in template strings (that start with the ` symbol)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
will likely have to search for token before opening bracket to determine if in template string
test with newfilterbuilder.js using state sub methods.
Is it possible to integrate this plugin using existing ACE by just adding an ext-tern from this library. Or we should use the ace editor completely from this repository?
As Google is slowly removing support for Chrome Apps in favor of PWAs and Chrome Extensions, are there plans to convert Caret-T to one or the other? Windows, Linux, and Mac support is already gone, and ChromeOS support will follow eventually.
Its okay to copy ext-tern.js from Caret-T as its Chrome App specific content has been removed. However, worker-tern.js can't be copied because it has ChromeApp junk in the header, so only copy all of the libs and the comments at the top of the header.
Usage of ace.tern in dynamic tab creation is resulting in tremendous memory increase.
The memory used for an editor in a tab will not be cleared, when the editor gets destroyed, this results in crashing the browser object.
A sample code used for the dynamic creation and termination of an editor
aceEditor = { append : function(editor,tabId){
var useWebWorker = true;
editor.getSession().setUseWorker(useWebWorker);
editor.session.setMode("ace/mode/javascript");
editor.getSession().setUseWrapMode(true);
editor.getSession().setWrapLimitRange(null, null);
editor.setShowPrintMargin(false);
ace.config.loadModule('ace/ext/language_tools', function() {
ace.config.loadModule('ace/ext/tern', function() {
editor.setOptions({
enableTern: {
defs: ['browser', 'ecma5', 'ourData'],
plugins: {
doc_comment: {
fullDocs: true
}
},
useWorker: useWebWorker,
switchToDoc: function(name, start) {
console.log('switchToDoc called but not defined. name=' + name + '; start=', start);
},
startedCb: function() {
console.log('editor.ternServer:', editor.ternServer);
},
},
enableSnippets: false,
enableBasicAutocompletion: true,
});
});
});
// Append editor into tabs using "tabId"
},
remove : function(editor,tabId){
editor.setSession(null);
editor.destroy();
// Remove tab from tabs using "tabId"
}
}
I don't even know what to call this, but here this is what I tend to get with your app http://imgur.com/4zYDNOP I thought it was because of my laptop suddenly shutting down but today I closed it before my laptop went off and still this happened. The image you see was my home page for a site I was working on.
There is a lot of functionality that is using custom functions that can be replaced by Ace's built in libs. Examples:
ace/lib/lang
exports.escapeHTML = function(str) {
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<");
};
Right now it will return the wrong position when there are parenthesis relatively close to current call (like on line before or after)
Tern won't support this as marijnh said its not a problem...
Use a quick and ghetto hack to make it work:
The real problem is marijnh refuses to support this, which is silly because find refs works but rename won't because marijnh says it won't work 100% of the time, but the whole idea of tern is its a best-effort add on.
https://github.com/c9/c9.ide.language.javascript.tern
https://github.com/c9/c9.ide.language.jsonalyzer
See get call position function:
function getCallNode(currentNode, cursorPos) {
var result;
currentNode.traverseUp(
'Call(e, args)', 'New(e, args)', function(b, node) {
result = node;
return node;
},
function(node) {
// Show tooltip only on first line if call spans multiple lines
var pos = node.getPos();
if (pos && pos.sl !== cursorPos.row)
return node;
}
);
return result;
}
Caret-T autocomplete feature runs very well.
Can you compare Ace.Tern autocomplete to Caret-T?
Is the following project status stated in the demo application still valid or is the current version suitable for production environment?
"Under heavy development, not ready for prime time yet"
"This demo is not isolated, it has extra stuff that is not related to the demo that needs to be removed"
@sevin7676 I had created a tern support for ACE https://github.com/angelozerr/tern.ace. Perhaps we could collaborae to avoid having several projects?
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?
I have seen, that you have a demo with html (mode). In this demo if you type some javascript anywhere (inside html content), altough js must be inserted inside script tag:
<html>
var s = "";
<script>
// here completion for s is available, although it should not.
</script>
</html>
To fix this problem you could integrates https://github.com/angelozerr/tern-browser-extension which parse your HTML with SAX and extract JS code from script tags. It gives you more features than completion for HTML elements ids, CSS selectors and event types.
I get the following error when I run demo.html locally.
Uncaught SecurityError: Failed to construct 'Worker': Script at 'file:///C:/Users/Desktop/Ace.Tern-master/ace-builds/src-noconflict/worker-tern.js' cannot be accessed from origin 'null'.
Is it not possible to run demo.html locally?
When tern uses the built in Ace Text Completed its very slow
This is not the case in the Ace Kitchen sink without Tern (test with large JS file)
Is the removing of duplicate entries causing the massive slow down?
Integrates https://github.com/angelozerr/tern-lint
See features at https://github.com/angelozerr/tern-lint/wiki/Validation-Rules
I noticed that this only works with Ace version 1.1.9. The latest version of Ace is 1.2.5. That has lots of bug fixes. Unfortunately you can't just replace Ace and its ext, modes, etc. The tern webworker seems to break with that. Any idea how to get this working with a newer version of Ace?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.