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 <officecfg/Office/BasicIDE.hxx>
23 #include <officecfg/Office/Common.hxx>
27 CodeCompleteOptions
& theCodeCompleteOptions()
29 static CodeCompleteOptions SINGLETON
;
34 CodeCompleteOptions::CodeCompleteOptions()
36 bIsAutoCorrectOn
= officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
37 bIsAutoCloseParenthesisOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
38 bIsAutoCloseQuotesOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
39 bIsProcedureAutoCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
40 bIsCodeCompleteOn
= officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
41 bExtendedTypeDeclarationOn
= officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
44 bool CodeCompleteOptions::IsCodeCompleteOn()
46 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsCodeCompleteOn
;
49 void CodeCompleteOptions::SetCodeCompleteOn( bool b
)
51 theCodeCompleteOptions().bIsCodeCompleteOn
= b
;
54 bool CodeCompleteOptions::IsExtendedTypeDeclaration()
56 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bExtendedTypeDeclarationOn
;
59 void CodeCompleteOptions::SetExtendedTypeDeclaration( bool b
)
61 theCodeCompleteOptions().bExtendedTypeDeclarationOn
= b
;
64 bool CodeCompleteOptions::IsProcedureAutoCompleteOn()
66 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsProcedureAutoCompleteOn
;
69 void CodeCompleteOptions::SetProcedureAutoCompleteOn( bool b
)
71 theCodeCompleteOptions().bIsProcedureAutoCompleteOn
= b
;
74 bool CodeCompleteOptions::IsAutoCloseQuotesOn()
76 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsAutoCloseQuotesOn
;
79 void CodeCompleteOptions::SetAutoCloseQuotesOn( bool b
)
81 theCodeCompleteOptions().bIsAutoCloseQuotesOn
= b
;
84 bool CodeCompleteOptions::IsAutoCloseParenthesisOn()
86 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsAutoCloseParenthesisOn
;
89 void CodeCompleteOptions::SetAutoCloseParenthesisOn( bool b
)
91 theCodeCompleteOptions().bIsAutoCloseParenthesisOn
= b
;
94 bool CodeCompleteOptions::IsAutoCorrectOn()
96 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsAutoCorrectOn
;
99 void CodeCompleteOptions::SetAutoCorrectOn( bool b
)
101 theCodeCompleteOptions().bIsAutoCorrectOn
= b
;
104 std::ostream
& operator<< (std::ostream
& aStream
, const CodeCompleteDataCache
& aCache
)
106 aStream
<< "Global variables" << std::endl
;
107 for (auto const& globalVar
: aCache
.aGlobalVars
)
109 aStream
<< globalVar
.first
<< "," << globalVar
.second
<< std::endl
;
111 aStream
<< "Local variables" << std::endl
;
112 for (auto const& varScope
: aCache
.aVarScopes
)
114 aStream
<< varScope
.first
<< std::endl
;
115 CodeCompleteVarTypes aVarTypes
= varScope
.second
;
116 for (auto const& varType
: aVarTypes
)
118 aStream
<< "\t" << varType
.first
<< "," << varType
.second
<< std::endl
;
121 aStream
<< "-----------------" << std::endl
;
125 void CodeCompleteDataCache::Clear()
131 void CodeCompleteDataCache::InsertGlobalVar( const OUString
& sVarName
, const OUString
& sVarType
)
133 aGlobalVars
.emplace( sVarName
, sVarType
);
136 void CodeCompleteDataCache::InsertLocalVar( const OUString
& sProcName
, const OUString
& sVarName
, const OUString
& sVarType
)
138 CodeCompleteVarScopes::const_iterator aIt
= aVarScopes
.find( sProcName
);
139 if( aIt
== aVarScopes
.end() ) //new procedure
141 CodeCompleteVarTypes aTypes
;
142 aTypes
.emplace( sVarName
, sVarType
);
143 aVarScopes
.emplace( sProcName
, aTypes
);
147 CodeCompleteVarTypes aTypes
= aVarScopes
[ sProcName
];
148 aTypes
.emplace( sVarName
, sVarType
);
149 aVarScopes
[ sProcName
] = std::move(aTypes
);
153 OUString
CodeCompleteDataCache::GetVarType( std::u16string_view sVarName
) const
155 for (auto const& varScope
: aVarScopes
)
157 CodeCompleteVarTypes aTypes
= varScope
.second
;
158 for (auto const& elem
: aTypes
)
160 if( elem
.first
.equalsIgnoreAsciiCase( sVarName
) )
166 //not a local, search global scope
167 for (auto const& globalVar
: aGlobalVars
)
169 if( globalVar
.first
.equalsIgnoreAsciiCase( sVarName
) )
170 return globalVar
.second
;
172 return OUString(); //not found
175 OUString
CodeCompleteDataCache::GetCorrectCaseVarName( std::u16string_view sVarName
, std::u16string_view sActProcName
) const
177 for (auto const& varScope
: aVarScopes
)
179 CodeCompleteVarTypes aTypes
= varScope
.second
;
180 for (auto const& elem
: aTypes
)
182 if( elem
.first
.equalsIgnoreAsciiCase( sVarName
) && varScope
.first
.equalsIgnoreAsciiCase( sActProcName
) )
188 // search global scope
189 for (auto const& globalVar
: aGlobalVars
)
191 if( globalVar
.first
.equalsIgnoreAsciiCase( sVarName
) )
192 return globalVar
.first
;
194 return OUString(); //not found
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */