Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 417958
Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.ui/web/orion/edit/ast.js (-8 / +44 lines)
Lines 33-38 Link Here
33
		this.start();
33
		this.start();
34
	}
34
	}
35
	objects.mixin(ASTManager.prototype, /** @lends orion.edit.ASTManager.prototype */ {
35
	objects.mixin(ASTManager.prototype, /** @lends orion.edit.ASTManager.prototype */ {
36
		/**
37
		 * @name start
38
		 * @description starts the manager, throws a nnew error if the manager has laready been started
39
		 * @function
40
		 * @public
41
		 * @memberof ASTManager.prototype
42
		 */
36
		start: function() {
43
		start: function() {
37
			if (this.registration) {
44
			if (this.registration) {
38
				throw new Error("Already started");
45
				throw new Error("Already started");
Lines 46-65 Link Here
46
				getAST: this.getAST.bind(this)
53
				getAST: this.getAST.bind(this)
47
			}, null); //$NON-NLS-0$
54
			}, null); //$NON-NLS-0$
48
		},
55
		},
56
		/**
57
		 * @name stop
58
		 * @description stops the manager, throws an error is the manager is not running
59
		 * @function
60
		 * @public
61
		 * @memberof ASTManager.prototype
62
		 */
49
		stop: function() {
63
		stop: function() {
64
			if(!this.registration) {
65
				throw new Error("Manager not running");
66
			}
50
			this.registration.unregister();
67
			this.registration.unregister();
51
			this.contextRegistration.unregister();
68
			this.contextRegistration.unregister();
52
			this.tracker.close();
69
			this.tracker.close();
53
			this.listener = this.cachedAST = null;
70
			this.listener = this.cachedAST = null;
54
		},
71
		},
55
		/**
72
		/**
56
		 * Notifies the AST manager of a change to the model.
73
		 * @name updated
74
		 * @description Notifies the AST manager of a change to the model.
75
		 * @function
76
		 * @public
77
		 * @memberof ASTManager.prototype
57
		 * @param {Object} event
78
		 * @param {Object} event
58
		 */
79
		 */
59
		updated: function(event) {
80
		updated: function(event) {
60
			this.cachedAST = null;
81
			this.cachedAST = null;
61
		},
82
		},
62
		/**
83
		/**
84
		 * @name _getASTProvider
85
		 * @description Returns the AST provider for the given content type id
86
		 * @function
87
		 * @private
88
		 * @memberof ASTManager.prototype
63
		 * @param {String} contentTypeId
89
		 * @param {String} contentTypeId
64
		 * @returns {Object} An AST provider capable of providing an AST for the given contentType.
90
		 * @returns {Object} An AST provider capable of providing an AST for the given contentType.
65
		 */
91
		 */
Lines 71-94 Link Here
71
			return serviceRef ? this.serviceRegistry.getService(serviceRef) : null;
97
			return serviceRef ? this.serviceRegistry.getService(serviceRef) : null;
72
		},
98
		},
73
		/**
99
		/**
74
		 * @param {String} contentTypeId
100
		 * @name _getAST
75
		 * @returns {Object|orion.Promise}
101
		 * @description Computes the AST for the given content type id and context
102
		 * @function
103
		 * @private
104
		 * @memberof ASTManager.prototype
105
		 * @param {String} contentTypeId the id of the content type to conpute the AST for
106
		 * @param {Object} astContext the context in which to compute the AST
107
		 * @returns {Object|orion.Promise} or <code>null</code> if there are no providers for an AST of the given content type
76
		 */
108
		 */
77
		_getAST: function(contentTypeId, options) {
109
		_getAST: function(contentTypeId, astContext) {
78
			if (this.cachedAST) {
110
			if (this.cachedAST) {
79
				return this.cachedAST;
111
				return this.cachedAST;
80
			}
112
			}
81
			var provider = this._getASTProvider(contentTypeId);
113
			var provider = this._getASTProvider(contentTypeId);
82
			if (provider) {
114
			if (provider) {
83
				options.text = this.inputManager.getEditor().getText();
115
				astContext.text = this.inputManager.getEditor().getText();
84
				return provider.computeAST(options);
116
				return provider.computeAST(astContext);
85
			}
117
			}
86
			return null;
118
			return null;
87
		},
119
		},
88
		/**
120
		/**
89
		 * Retrieves an AST from a capable AST provider.
121
		 * @name getAST
122
		 * @description Retrieves an AST from a capable AST provider.
123
		 * @function
124
		 * @public
125
		 * @memberof ASTManager.prototype
90
		 * @param {Object} [options={}] Options to be passed to the AST provider.
126
		 * @param {Object} [options={}] Options to be passed to the AST provider.
91
		 * @returns {orion.Promise} A promise that resolves to the AST. Resolves to <code>null</code> if no capable provider was found.
127
		 * @returns {Object|orion.Promise} A promise that resolves to the AST. Resolves to <code>null</code> if no capable provider was found.
92
		 */
128
		 */
93
		getAST: function(options) {
129
		getAST: function(options) {
94
			options = options || {};
130
			options = options || {};

Return to bug 417958