I was recently thinking about code-switching (i.e. switching between languages within a sentence, social exchange, phrase, etc.) Would switching between dialects or accents of the same language under those same situations be considered code-switching? Is there a certain 'distance' - in terms of structure and usage - that a dialect or accent has to be away from the main language to be considered code-switching?
There's in no clear cut definition of code switching with respect to language distance. In fact, there is no universally shared definition of code switching - although scholars generally talk about the same range of phenomena. The concept was originally developed to account for switching between two distinct languages during conversation among bilingual speakers of English and Spanish. This is still the stereotypical example in linguistics textbooks where code switching is also closely associated with diglossia.
However, scholars have used the term even when it comes to quite close varieties of a language from AAVE to Czech alterations in standard and non-standard morphology or Norwegian standard and non-standard usage.
You also have to consider the whole range of uses to which code switching is subject ranging across things like filling gaps in linguistic knowledge, humor, in-group identification, social function, etc. These can all happen with very similar or distinct codes.
In fact, I would argue that code switching is a very useful term to apply even between registers of the same variety. If you consider snippets like "Then Frank spoken unto Karen." or "Ladies and Gentlemen we are well and truly fucked." both the speaker and the listeners have to employ very similar cognition and world knowledge as they do in code switching between typologically or genetically distinct languages. A type of code switching is also a feature of conversation in groups with mixed politeness requirements among speakers all speaking in the same register.
When I teach linguistics to language teachers, I always put special emphasis on code switching because they are likely to encounter a version of it with their students who have to learn a new variety of both school and written style language. Teachers have a tendency to treat all other codes as 'wrong' versions of what the standard which they consider the language. In many cases, accents and dialects make things even more complicated for them with many historical examples of abuse by the school system.
Paradoxically, there are many examples of borrowing like "He has a certain je ne sais quoi" are not generally meaningful examples of code switching between English and French - but could be examples of code switching between registers.
This paper has a very nice overview of the history of the term code switching even though it does not address the question of closeness directly.