Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Titan Language Server
Manage
Activity
Members
Labels
Plan
Issues
35
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
Eclipse Titan
Titan Language Server
Merge requests
!302
Add FriendModuleContext
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add FriendModuleContext
friendModuleCompletion
into
main
Overview
0
Commits
1
Changes
1
Merged
Csilla Farkas
requested to merge
friendModuleCompletion
into
main
1 year ago
Overview
0
Commits
1
Changes
1
Expand
Signed-off-by: Csilla Farkas
csilla.farkas@sigmatechnology.com
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
fa137943
1 commit,
1 year ago
1 file
+
133
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
lsp/src/main/java/org/eclipse/titan/lsp/completion/FriendModuleContext.java
0 → 100644
+
133
−
0
Options
/******************************************************************************
* Copyright (c) 2000-2023 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package
org.eclipse.titan.lsp.completion
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.eclipse.lsp4j.CompletionItem
;
import
org.eclipse.lsp4j.CompletionItemKind
;
import
org.eclipse.lsp4j.CompletionList
;
import
org.eclipse.lsp4j.InsertReplaceEdit
;
import
org.eclipse.lsp4j.jsonrpc.messages.Either
;
import
org.eclipse.titan.lsp.AST.Module
;
import
org.eclipse.titan.lsp.AST.TTCN3.definitions.FriendModule
;
import
org.eclipse.titan.lsp.AST.TTCN3.definitions.TTCN3Module
;
import
org.eclipse.titan.lsp.core.Position
;
import
org.eclipse.titan.lsp.core.Project
;
import
org.eclipse.titan.lsp.core.ProjectItem
;
import
org.eclipse.titan.lsp.core.Range
;
public
class
FriendModuleContext
extends
CompletionContext
{
public
FriendModuleContext
(
CompletionContextInfo
contextInfo
)
{
super
(
contextInfo
);
}
private
List
<
String
>
parseFriendModules
()
{
List
<
String
>
friendModuleList
=
new
ArrayList
<>();
final
String
friendModules
=
contextInfo
.
matcher
.
group
(
1
);
if
(
friendModules
!=
null
)
{
friendModuleList
=
new
ArrayList
<>(
List
.
of
(
friendModules
.
split
(
","
)))
.
stream
()
.
map
(
mName
->
mName
.
replaceAll
(
"\\s"
,
""
))
.
collect
(
Collectors
.
toList
());
}
return
friendModuleList
;
}
private
boolean
isProperProjectItem
(
ProjectItem
projectItem
,
TTCN3Module
actualModule
)
{
if
(
projectItem
.
isExcluded
())
{
return
false
;
}
final
Module
importableModule
=
projectItem
.
getModule
();
if
(
importableModule
==
null
||
importableModule
==
actualModule
)
{
return
false
;
}
if
(
actualModule
.
getImportedModules
().
contains
(
importableModule
))
{
return
false
;
}
return
true
;
}
private
List
<
CompletionItem
>
collectCompletionItems
(
TTCN3Module
actualModule
)
{
final
Project
project
=
actualModule
.
getProject
();
final
List
<
CompletionItem
>
completions
=
new
ArrayList
<>();
final
List
<
FriendModule
>
parsedFriendModules
=
actualModule
.
getFriendModules
();
final
List
<
String
>
friendModuleList
=
parseFriendModules
();
project
.
getAllProjectItems
().
entrySet
().
forEach
(
entry
->
{
final
ProjectItem
projectItem
=
entry
.
getValue
();
if
(!
isProperProjectItem
(
projectItem
,
actualModule
))
{
return
;
}
final
String
importableModuleName
=
projectItem
.
getModule
().
getIdentifier
().
getDisplayName
();
if
(
friendModuleList
.
contains
(
importableModuleName
))
{
return
;
}
FriendModule
onParsedFriendModule
=
null
;
for
(
FriendModule
friend
:
parsedFriendModules
)
{
if
(
friend
.
getIdentifier
().
getDisplayName
().
equals
(
importableModuleName
))
{
return
;
}
if
(
friend
.
getLocation
().
containsPosition
(
contextInfo
.
cursorPosition
))
{
onParsedFriendModule
=
friend
;
}
}
Range
replacementRange
=
null
;
if
(
onParsedFriendModule
!=
null
)
{
replacementRange
=
onParsedFriendModule
.
getIdentifier
().
getLocation
().
getRange
();
}
else
if
(
friendModuleList
.
size
()
>
0
)
{
final
Position
replacementStart
=
new
Position
(
contextInfo
.
cursorPosition
.
getLine
(),
contextInfo
.
cursorPosition
.
getCharacter
()
-
friendModuleList
.
get
(
friendModuleList
.
size
()
-
1
).
length
()
);
replacementRange
=
new
Range
(
replacementStart
,
contextInfo
.
cursorPosition
);
}
final
CompletionItem
completionItem
=
new
CompletionItem
();
completionItem
.
setLabel
(
importableModuleName
);
completionItem
.
setInsertText
(
importableModuleName
);
completionItem
.
setKind
(
CompletionItemKind
.
Module
);
if
(
replacementRange
!=
null
)
{
final
InsertReplaceEdit
insRepEdit
=
new
InsertReplaceEdit
();
insRepEdit
.
setInsert
(
replacementRange
);
insRepEdit
.
setReplace
(
replacementRange
);
insRepEdit
.
setNewText
(
completionItem
.
getInsertText
());
completionItem
.
setTextEdit
(
Either
.
forRight
(
insRepEdit
));
}
completions
.
add
(
completionItem
);
});
return
completions
;
}
@Override
public
Either
<
List
<
CompletionItem
>,
CompletionList
>
getCompletion
()
{
final
Module
module
=
contextInfo
.
module
;
if
(
module
==
null
)
{
return
null
;
}
if
(
module
instanceof
TTCN3Module
)
{
final
List
<
CompletionItem
>
completionList
=
collectCompletionItems
((
TTCN3Module
)
module
);
return
Either
.
forLeft
(
completionList
);
}
return
null
;
}
}
Loading