@@ -521,6 +521,7 @@ def jedi_script(self, position=None, use_document_path=False):
521
521
extra_paths = []
522
522
environment_path = None
523
523
env_vars = None
524
+ prioritize_extra_paths = False
524
525
525
526
if self ._config :
526
527
jedi_settings = self ._config .plugin_settings (
@@ -537,19 +538,19 @@ def jedi_script(self, position=None, use_document_path=False):
537
538
538
539
extra_paths = jedi_settings .get ("extra_paths" ) or []
539
540
env_vars = jedi_settings .get ("env_vars" )
541
+ prioritize_extra_paths = jedi_settings .get ("prioritize_extra_paths" )
540
542
541
- # Drop PYTHONPATH from env_vars before creating the environment because that makes
542
- # Jedi throw an error .
543
+ # Drop PYTHONPATH from env_vars before creating the environment to
544
+ # ensure that Jedi can startup properly without module name collision .
543
545
if env_vars is None :
544
546
env_vars = os .environ .copy ()
545
547
env_vars .pop ("PYTHONPATH" , None )
546
548
547
- environment = (
548
- self .get_enviroment (environment_path , env_vars = env_vars )
549
- if environment_path
550
- else None
549
+ environment = self .get_enviroment (environment_path , env_vars = env_vars )
550
+ sys_path = self .sys_path (
551
+ environment_path , env_vars , prioritize_extra_paths , extra_paths
551
552
)
552
- sys_path = self . sys_path ( environment_path , env_vars = env_vars ) + extra_paths
553
+
553
554
project_path = self ._workspace .root_path
554
555
555
556
# Extend sys_path with document's path if requested
@@ -559,7 +560,7 @@ def jedi_script(self, position=None, use_document_path=False):
559
560
kwargs = {
560
561
"code" : self .source ,
561
562
"path" : self .path ,
562
- "environment" : environment ,
563
+ "environment" : environment if environment_path else None ,
563
564
"project" : jedi .Project (path = project_path , sys_path = sys_path ),
564
565
}
565
566
@@ -584,14 +585,24 @@ def get_enviroment(self, environment_path=None, env_vars=None):
584
585
585
586
return environment
586
587
587
- def sys_path (self , environment_path = None , env_vars = None ):
588
+ def sys_path (
589
+ self ,
590
+ environment_path = None ,
591
+ env_vars = None ,
592
+ prioritize_extra_paths = False ,
593
+ extra_paths = [],
594
+ ):
588
595
# Copy our extra sys path
589
- # TODO: when safe to break API, use env_vars explicitly to pass to create_environment
590
596
path = list (self ._extra_sys_path )
591
597
environment = self .get_enviroment (
592
598
environment_path = environment_path , env_vars = env_vars
593
599
)
594
600
path .extend (environment .get_sys_path ())
601
+ if prioritize_extra_paths :
602
+ path += extra_paths + path
603
+ else :
604
+ path += path + extra_paths
605
+
595
606
return path
596
607
597
608
0 commit comments