From 6098bfce815c30a6b1885e20131bc77ea7729fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Sat, 9 Mar 2013 00:48:00 +0000 Subject: [PATCH] add example --- example/main.js | 56 +++++++++++++++++++++++++++++++++++ example/name_of_other_file.js | 5 ++++ example/name_of_the_file.js | 3 ++ 3 files changed, 64 insertions(+) create mode 100644 example/main.js create mode 100644 example/name_of_other_file.js create mode 100644 example/name_of_the_file.js diff --git a/example/main.js b/example/main.js new file mode 100644 index 00000000..410da659 --- /dev/null +++ b/example/main.js @@ -0,0 +1,56 @@ +var fs = require('fs') +var tern = require('../') +var acorn = require('acorn') +var path = require('path') + +var environment = [ + JSON.parse(fs.readFileSync('ecma5.json')), + JSON.parse(fs.readFileSync('browser.json')) +] + +var files = { + 'name_of_the_file.js': fs.readFileSync(path.join(__dirname, 'name_of_the_file.js'), 'utf8'), + 'name_of_other_file.js': fs.readFileSync(path.join(__dirname, 'name_of_other_file.js'), 'utf8') +} + +var getFile = function (name, callback) { + callback(null, files[name]) +} + +var server = new tern.Server({getFile: getFile}, environment) + +server.addFile('name_of_the_file.js') +server.addFile('name_of_other_file.js') + + + +server.request({ + query: { + type: 'completions', + end: 8, + file: 'name_of_the_file.js' + }, + files: [ + { + type: 'full', + name: 'name_of_the_file.js', + text: files['name_of_the_file.js'] + } + ] +}, function (e, data) { + if(e) throw e + console.log(require('util').inspect(data.completions)); +}) + + +server.request({ + query: { + type: 'type', + end: 39, + file: 'name_of_other_file.js' + }, + files: [] +}, function (e, data) { + if(e) throw e + console.log(require('util').inspect(data)); +}) \ No newline at end of file diff --git a/example/name_of_other_file.js b/example/name_of_other_file.js new file mode 100644 index 00000000..1d389031 --- /dev/null +++ b/example/name_of_other_file.js @@ -0,0 +1,5 @@ +var fn = function (a) {return a+10}; + +fn + +var b = "" \ No newline at end of file diff --git a/example/name_of_the_file.js b/example/name_of_the_file.js new file mode 100644 index 00000000..4c118225 --- /dev/null +++ b/example/name_of_the_file.js @@ -0,0 +1,3 @@ +console. + +var a = [] \ No newline at end of file