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>
27 class theCodeCompleteOptions
: public ::rtl::Static
< CodeCompleteOptions
, theCodeCompleteOptions
>{};
30 CodeCompleteOptions::CodeCompleteOptions()
32 bIsAutoCorrectOn
= officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
33 bIsAutoCloseParenthesisOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
34 bIsAutoCloseQuotesOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
35 bIsProcedureAutoCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
36 bIsCodeCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
37 bExtendedTypeDeclarationOn
= officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
40 bool CodeCompleteOptions::IsCodeCompleteOn()
42 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsCodeCompleteOn
;
45 void CodeCompleteOptions::SetCodeCompleteOn( bool b
)
47 theCodeCompleteOptions::get().bIsCodeCompleteOn
= b
;
50 bool CodeCompleteOptions::IsExtendedTypeDeclaration()
52 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bExtendedTypeDeclarationOn
;
55 void CodeCompleteOptions::SetExtendedTypeDeclaration( bool b
)
57 theCodeCompleteOptions::get().bExtendedTypeDeclarationOn
= b
;
60 bool CodeCompleteOptions::IsProcedureAutoCompleteOn()
62 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn
;
65 void CodeCompleteOptions::SetProcedureAutoCompleteOn( bool b
)
67 theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn
= b
;
70 bool CodeCompleteOptions::IsAutoCloseQuotesOn()
72 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseQuotesOn
;
75 void CodeCompleteOptions::SetAutoCloseQuotesOn( bool b
)
77 theCodeCompleteOptions::get().bIsAutoCloseQuotesOn
= b
;
80 bool CodeCompleteOptions::IsAutoCloseParenthesisOn()
82 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn
;
85 void CodeCompleteOptions::SetAutoCloseParenthesisOn( bool b
)
87 theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn
= b
;
90 bool CodeCompleteOptions::IsAutoCorrectOn()
92 return theCodeCompleteOptions::get().aMiscOptions
.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCorrectOn
;
95 void CodeCompleteOptions::SetAutoCorrectOn( bool b
)
97 theCodeCompleteOptions::get().bIsAutoCorrectOn
= b
;
100 std::ostream
& operator<< (std::ostream
& aStream
, const CodeCompleteDataCache
& aCache
)
102 aStream
<< "Global variables" << std::endl
;
103 for (auto const& globalVar
: aCache
.aGlobalVars
)
105 aStream
<< globalVar
.first
<< "," << globalVar
.second
<< std::endl
;
107 aStream
<< "Local variables" << std::endl
;
108 for (auto const& varScope
: aCache
.aVarScopes
)
110 aStream
<< varScope
.first
<< std::endl
;
111 CodeCompleteVarTypes aVarTypes
= varScope
.second
;
112 for (auto const& varType
: aVarTypes
)
114 aStream
<< "\t" << varType
.first
<< "," << varType
.second
<< std::endl
;
117 aStream
<< "-----------------" << std::endl
;
121 void CodeCompleteDataCache::Clear()
127 void CodeCompleteDataCache::InsertGlobalVar( const OUString
& sVarName
, const OUString
& sVarType
)
129 aGlobalVars
.emplace( sVarName
, sVarType
);
132 void CodeCompleteDataCache::InsertLocalVar( const OUString
& sProcName
, const OUString
& sVarName
, const OUString
& sVarType
)
134 CodeCompleteVarScopes::const_iterator aIt
= aVarScopes
.find( sProcName
);
135 if( aIt
== aVarScopes
.end() ) //new procedure
137 CodeCompleteVarTypes aTypes
;
138 aTypes
.emplace( sVarName
, sVarType
);
139 aVarScopes
.emplace( sProcName
, aTypes
);
143 CodeCompleteVarTypes aTypes
= aVarScopes
[ sProcName
];
144 aTypes
.emplace( sVarName
, sVarType
);
145 aVarScopes
[ sProcName
] = aTypes
;
149 OUString
CodeCompleteDataCache::GetVarType( const OUString
& sVarName
) const
151 for (auto const& varScope
: aVarScopes
)
153 CodeCompleteVarTypes aTypes
= varScope
.second
;
154 for (auto const& elem
: aTypes
)
156 if( elem
.first
.equalsIgnoreAsciiCase( sVarName
) )
162 //not a local, search global scope
163 for (auto const& globalVar
: aGlobalVars
)
165 if( globalVar
.first
.equalsIgnoreAsciiCase( sVarName
) )
166 return globalVar
.second
;
168 return OUString(); //not found
171 OUString
CodeCompleteDataCache::GetCorrectCaseVarName( const OUString
& sVarName
, const OUString
& sActProcName
) const
173 for (auto const& varScope
: aVarScopes
)
175 CodeCompleteVarTypes aTypes
= varScope
.second
;
176 for (auto const& elem
: aTypes
)
178 if( elem
.first
.equalsIgnoreAsciiCase( sVarName
) && varScope
.first
.equalsIgnoreAsciiCase( sActProcName
) )
184 // search global scope
185 for (auto const& globalVar
: aGlobalVars
)
187 if( globalVar
.first
.equalsIgnoreAsciiCase( sVarName
) )
188 return globalVar
.first
;
190 return OUString(); //not found
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */