| 3210 | } |
| 3211 | |
| 3212 | void LLMChatUI::insertFileToDocument( std::string path, std::shared_ptr<TextDocument> cdoc ) { |
| 3213 | std::string prjPath( getPlugin()->getPluginContext()->getCurrentProject() ); |
| 3214 | |
| 3215 | if ( FileSystem::isRelativePath( path ) ) |
| 3216 | path = prjPath + path; |
| 3217 | |
| 3218 | TextDocument doc; |
| 3219 | if ( doc.loadFromFile( path ) == TextDocument::LoadStatus::Loaded ) { |
| 3220 | std::string nameToDisplay = doc.getFilename(); |
| 3221 | if ( !prjPath.empty() && String::startsWith( doc.getFilePath(), prjPath ) ) { |
| 3222 | nameToDisplay = doc.getFilePath(); |
| 3223 | FileSystem::filePathRemoveBasePath( prjPath, nameToDisplay ); |
| 3224 | } |
| 3225 | cdoc->resetSelection(); |
| 3226 | cdoc->moveToEndOfLine(); |
| 3227 | cdoc->textInput( "\n`" + nameToDisplay + "`:\n" ); |
| 3228 | cdoc->textInput( "```" + doc.getSyntaxDefinition().getLSPName() ); |
| 3229 | auto lineToFold = cdoc->getSelection().end().line(); |
| 3230 | if ( doc.linesCount() >= 1 && !String::startsWith( doc.line( 0 ).getText(), "\n" ) ) { |
| 3231 | cdoc->textInput( "\n" ); |
| 3232 | } |
| 3233 | cdoc->textInput( doc.getText() ); |
| 3234 | if ( doc.linesCount() >= 1 && |
| 3235 | doc.line( doc.linesCount() - 1 ).getText() != String( "\n" ) ) { |
| 3236 | cdoc->textInput( "\n" ); |
| 3237 | } |
| 3238 | cdoc->textInput( "```\n" ); |
| 3239 | cdoc->getFoldRangeService().findRegionsNative(); |
| 3240 | if ( doc.linesCount() > 30 && |
| 3241 | cdoc->getFoldRangeService().isFoldingRegionInLine( lineToFold ) ) { |
| 3242 | mChatInput->toggleFoldUnfold( lineToFold ); |
| 3243 | } |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | void LLMChatUI::initAttachFile() { |
| 3248 | mLocateBarLayout = findByClass<UIVLinearLayoutCommandExecuter>( "llm_chat_attach" ); |
nothing calls this directly
no test coverage detected