1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <basic/codecompletecache.hxx>
22 #include <rtl/instance.hxx>
23 #include <officecfg/Office/BasicIDE.hxx>
24 #include <officecfg/Office/Common.hxx>
28 class theCodeCompleteOptions
: public ::rtl::Static
< CodeCompleteOptions
, theCodeCompleteOptions
>{};
31 CodeCompleteOptions::CodeCompleteOptions()
33 bIsAutoCorrectOn
= officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
34 bIsAutoCloseParenthesisOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
35 bIsAutoCloseQuotesOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
36 bIsProcedureAutoCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
37 bIsCodeCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
38 bExtendedTypeDeclarationOn
= officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
41 bool CodeCompleteOptions::IsCodeCompleteOn()
43 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions::get().bIsCodeCompleteOn
;
46 void CodeCompleteOptions::SetCodeCompleteOn( bool b
)
48 theCodeCompleteOptions::get().bIsCodeCompleteOn
= b
;
51 bool CodeCompleteOptions::IsExtendedTypeDeclaration()
53 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions::get().bExtendedTypeDeclarationOn
;
56 void CodeCompleteOptions::SetExtendedTypeDeclaration( bool b
)
58 theCodeCompleteOptions::get().bExtendedTypeDeclarationOn
= b
;
61 bool CodeCompleteOptions::IsProcedureAutoCompleteOn()
63 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn
;
66 void CodeCompleteOptions::SetProcedureAutoCompleteOn( bool b
)
68 theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn
= b
;
71 bool CodeCompleteOptions::IsAutoCloseQuotesOn()
73 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions::get().bIsAutoCloseQuotesOn
;
76 void CodeCompleteOptions::SetAutoCloseQuotesOn( bool b
)
78 theCodeCompleteOptions::get().bIsAutoCloseQuotesOn
= b
;
81 bool CodeCompleteOptions::IsAutoCloseParenthesisOn()
83 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn
;
86 void CodeCompleteOptions::SetAutoCloseParenthesisOn( bool b
)
88 theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn
= b
;
91 bool CodeCompleteOptions::IsAutoCorrectOn()
93 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions::get().bIsAutoCorrectOn
;
96 void CodeCompleteOptions::SetAutoCorrectOn( bool b
)
98 theCodeCompleteOptions::get().bIsAutoCorrectOn
= b
;
101 std::ostream
& operator<< (std::ostream
& aStream
, const CodeCompleteDataCache
& aCache
)
103 aStream
<< "Global variables" << std::endl
;
104 for (auto const& globalVar
: aCache
.aGlobalVars
)
106 aStream
<< globalVar
.first
<< "," << globalVar
.second
<< std::endl
;
108 aStream
<< "Local variables" << std::endl
;
109 for (auto const& varScope
: aCache
.aVarScopes
)
111 aStream
<< varScope
.first
<< std::endl
;
112 CodeCompleteVarTypes aVarTypes
= varScope
.second
;
113 for (auto const& varType
: aVarTypes
)
115 aStream
<< "\t" << varType
.first
<< "," << varType
.second
<< std::endl
;
118 aStream
<< "-----------------" << std::endl
;
122 void CodeCompleteDataCache::Clear()
128 void CodeCompleteDataCache::InsertGlobalVar( const OUString
& sVarName
, const OUString
& sVarType
)
130 aGlobalVars
.emplace( sVarName
, sVarType
);
133 void CodeCompleteDataCache::InsertLocalVar( const OUString
& sProcName
, const OUString
& sVarName
, const OUString
& sVarType
)
135 CodeCompleteVarScopes::const_iterator aIt
= aVarScopes
.find( sProcName
);
136 if( aIt
== aVarScopes
.end() ) //new procedure
138 CodeCompleteVarTypes aTypes
;
139 aTypes
.emplace( sVarName
, sVarType
);
140 aVarScopes
.emplace( sProcName
, aTypes
);
144 CodeCompleteVarTypes aTypes
= aVarScopes
[ sProcName
];
145 aTypes
.emplace( sVarName
, sVarType
);
146 aVarScopes
[ sProcName
] = aTypes
;
150 OUString
CodeCompleteDataCache::GetVarType( std::u16string_view sVarName
) const
152 for (auto const& varScope
: aVarScopes
)
154 CodeCompleteVarTypes aTypes
= varScope
.second
;
155 for (auto const& elem
: aTypes
)
157 if( elem
.first
.equalsIgnoreAsciiCase( sVarName
) )
163 //not a local, search global scope
164 for (auto const& globalVar
: aGlobalVars
)
166 if( globalVar
.first
.equalsIgnoreAsciiCase( sVarName
) )
167 return globalVar
.second
;
169 return OUString(); //not found
172 OUString
CodeCompleteDataCache::GetCorrectCaseVarName( std::u16string_view sVarName
, std::u16string_view sActProcName
) const
174 for (auto const& varScope
: aVarScopes
)
176 CodeCompleteVarTypes aTypes
= varScope
.second
;
177 for (auto const& elem
: aTypes
)
179 if( elem
.first
.equalsIgnoreAsciiCase( sVarName
) && varScope
.first
.equalsIgnoreAsciiCase( sActProcName
) )
185 // search global scope
186 for (auto const& globalVar
: aGlobalVars
)
188 if( globalVar
.first
.equalsIgnoreAsciiCase( sVarName
) )
189 return globalVar
.first
;
191 return OUString(); //not found
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */