@@ -225,5 +225,54 @@ file."
225
225
(semantic-find-tags-by-class 'include
226
226
(semantic-flatten-tags-table table)))
227
227
228
+ (define-mode-local-override semantic-documentation-for-tag
229
+ php-mode (&optional tag nosnarf)
230
+ " Find documentation from TAG and return it as a clean string.
231
+
232
+ TAG might have DOCUMENTATION set in it already. If not, there may be
233
+ some documentation in a comment preceding TAG's definition which we
234
+ can look for. When appropriate, this can be overridden by a language specific
235
+ enhancement.
236
+ Optional argument NOSNARF means to only return the lexical analyzer token for it.
237
+ If nosnarf if 'lex, then only return the lex token."
238
+ (let ((docstring (semantic-tag-get-attribute tag :documentation )))
239
+ (unless (stringp docstring)
240
+ (setq docstring (semantic-php-doc-snarf-comment-for-tag tag))
241
+ (semantic-tag-put-attribute tag :documentation docstring))
242
+ docstring))
243
+
244
+ (defun semantic-php-doc-snarf-comment-for-tag (tag )
245
+ " Extract a docstring from the docblock preceding TAG.
246
+
247
+ semantic-php does not use semantic-doc-snarf-comment-for-tag:
248
+ * snarf-comment-for-tag makes assumptions on the character
249
+ classes inside the documentation string, this is very error
250
+ prone and fails for common cases like when embedding URLs in
251
+ the comment
252
+ * semantic requires comment-end which is not set by cc-mode or php-mode"
253
+ (let ((docblock " " )
254
+ (docstring " " ))
255
+ (save-excursion
256
+ ; ; Find the tag.
257
+ (semantic-go-to-tag tag)
258
+ (beginning-of-line )
259
+ (backward-char )
260
+
261
+ ; ; Extract the docblock contents.
262
+ (when (looking-back " \* /" )
263
+ (let ((docend (match-beginning 0 ))
264
+ docstart)
265
+ (when (search-backward " /\*\* " nil t )
266
+ (setq docstart (match-end 0 )
267
+ docblock (buffer-substring-no-properties docstart docend))))))
268
+
269
+ ; ; Split the contents and produce a docstring.
270
+ (dolist (line (split-string docblock " \n " t ) docstring)
271
+ (setq line (string-trim line))
272
+ (setq docstring (concat docstring
273
+ " \n "
274
+ (if (not (string= " *" line))
275
+ (string-remove-prefix " * " line)))))))
276
+
228
277
(provide 'semantic-php )
229
278
; ;; semantic-php.el ends here
0 commit comments