Tools__CodeCompletionService.st
author Claus Gittinger <cg@exept.de>
Wed, 05 Jun 2019 14:16:59 +0200
changeset 18805 f6df57c6dbfb
parent 16980 46aba5fba348
child 17136 cb908d2ba02e
permissions -rw-r--r--
#BUGFIX by cg class: AbstractFileBrowser changed: #currentFileNameHolder endless loop if file not present.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
10075
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     2
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     3
              All Rights Reserved
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
10075
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     5
Permission is hereby granted, free of charge, to any person
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     6
obtaining a copy of this software and associated documentation
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     7
files (the 'Software'), to deal in the Software without
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     8
restriction, including without limitation the rights to use,
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
     9
copy, modify, merge, publish, distribute, sublicense, and/or sell
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    10
copies of the Software, and to permit persons to whom the
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    11
Software is furnished to do so, subject to the following
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    12
conditions:
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    13
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    14
The above copyright notice and this permission notice shall be
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    15
included in all copies or substantial portions of the Software.
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    16
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    17
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    18
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    19
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    20
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    21
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    22
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    23
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    24
OTHER DEALINGS IN THE SOFTWARE.
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"{ Package: 'stx:libtool' }"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"{ NameSpace: Tools }"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
CodeViewService subclass:#CodeCompletionService
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	instanceVariableNames:''
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	classVariableNames:''
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	poolDictionaries:''
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	category:'Interface-CodeView'
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!CodeCompletionService class methodsFor:'documentation'!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
copyright
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
10075
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    41
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    42
              All Rights Reserved
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    43
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    44
Permission is hereby granted, free of charge, to any person
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    45
obtaining a copy of this software and associated documentation
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    46
files (the 'Software'), to deal in the Software without
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    47
restriction, including without limitation the rights to use,
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    48
copy, modify, merge, publish, distribute, sublicense, and/or sell
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    49
copies of the Software, and to permit persons to whom the
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    50
Software is furnished to do so, subject to the following
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    51
conditions:
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
10075
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    53
The above copyright notice and this permission notice shall be
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    54
included in all copies or substantial portions of the Software.
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    55
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    56
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    57
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    58
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    59
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    60
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    61
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    62
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
9678631201b9 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 9981
diff changeset
    63
OTHER DEALINGS IN THE SOFTWARE.
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
! !
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
16363
29ee1ee25529 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 13558
diff changeset
    67
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
!CodeCompletionService class methodsFor:'accessing'!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
label
13100
ee16ab69a969 class: Tools::LintService
Claus Gittinger <cg@exept.de>
parents: 10413
diff changeset
    71
    "Answers a short label - for UI"
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    ^'Code Completion'
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "Created: / 07-03-2010 / 14:00:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
! !
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
!CodeCompletionService class methodsFor:'testing'!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
isAvailable
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    "CodeCompletionService is superseded by SmallSense"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
10259
45e2c87eddaf Merged with JV's branch
vrany
parents: 10075
diff changeset
    84
    "^(Smalltalk at:#SmallSenseService) isNil"
45e2c87eddaf Merged with JV's branch
vrany
parents: 10075
diff changeset
    85
10274
baa3a285f686 changed: #isAvailable
Claus Gittinger <cg@exept.de>
parents: 10259
diff changeset
    86
    "Sure, it is broken, but we need it!!"
10302
c24d8afc3661 changed: #isAvailable
vrany
parents: 10274
diff changeset
    87
    "JV2011-07-09: And I preferr SmallSense: this should work for both
c24d8afc3661 changed: #isAvailable
vrany
parents: 10274
diff changeset
    88
     unless SmallSense is loaded in your image"
10259
45e2c87eddaf Merged with JV's branch
vrany
parents: 10075
diff changeset
    89
10302
c24d8afc3661 changed: #isAvailable
vrany
parents: 10274
diff changeset
    90
    ^(Smalltalk at:#SmallSenseService) isNil.
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    "Created: / 03-04-2011 / 23:08:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10274
baa3a285f686 changed: #isAvailable
Claus Gittinger <cg@exept.de>
parents: 10259
diff changeset
    93
    "Modified: / 08-07-2011 / 08:42:52 / cg"
10413
87cc499c0b60 Fixes for debugger
vrany
parents: 10302
diff changeset
    94
    "Modified: / 27-07-2011 / 11:47:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
13204
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
    95
!
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
    96
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
    97
isUsefulFor:aCodeView
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
    98
    "this filters useful services.
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
    99
     Redefined to return true for myself - not for subclasses"
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
   100
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
   101
    ^ self == Tools::CodeCompletionService
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
   102
7dbb1dd9c4af class: Tools::XXXService
Claus Gittinger <cg@exept.de>
parents: 13100
diff changeset
   103
    "Created: / 22-07-2013 / 13:59:54 / cg"
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
! !
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
!CodeCompletionService methodsFor:'event handling'!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
keyPress: key x:x y:y in: view
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "Handles an event in given view (a subview of codeView).
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
     If the method returns true, the event will not be processed
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
     by the view."
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
16980
46aba5fba348 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 16363
diff changeset
   113
    (view == textView and:[key == #'CodeCompletion']) ifTrue:[
46aba5fba348 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 16363
diff changeset
   114
        self complete. 
46aba5fba348 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 16363
diff changeset
   115
        ^ true
46aba5fba348 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 16363
diff changeset
   116
    ].
46aba5fba348 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 16363
diff changeset
   117
    ^ false
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
! !
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
!CodeCompletionService methodsFor:'private'!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
complete
13445
72f632746eb4 class: Tools::CodeCompletionService
Claus Gittinger <cg@exept.de>
parents: 13204
diff changeset
   125
    |cls|
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
16363
29ee1ee25529 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 13558
diff changeset
   127
    codeView languageHolder value isSmalltalk ifFalse:[^self].
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    cls := codeView classHolder value.
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    cls isNil ifTrue:[
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
        self showInfo:'No class'.
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
        ^ self.
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    ].
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    UserInformation handle:[:ex |
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
        codeView showInfo:(ex messageText).
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
        ex proceed.
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    ] do:[
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
        codeView withWaitCursorDo:[
13558
70dbfd5f726d Pass programming language when asking DWIM to complete code
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13445
diff changeset
   139
            DoWhatIMeanSupport codeCompletionForLanguage: codeView language class:cls context:nil codeView:textView.
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
        ]
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    ].
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    ^ self.
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    "Modified: / 04-07-2006 / 18:48:26 / fm"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    "Modified: / 20-11-2006 / 12:30:59 / cg"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    "Created: / 07-03-2010 / 09:37:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
! !
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
!CodeCompletionService class methodsFor:'documentation'!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
version_CVS
16363
29ee1ee25529 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 13558
diff changeset
   152
    ^ '$Header$'
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
version_SVN
16363
29ee1ee25529 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 13558
diff changeset
   156
    ^ '$Id$'
9981
eae0ede9097e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
! !
13100
ee16ab69a969 class: Tools::LintService
Claus Gittinger <cg@exept.de>
parents: 10413
diff changeset
   158