@@ -107,14 +107,14 @@ def is_local(self):
107
107
return (self ._root_uri_scheme == '' or self ._root_uri_scheme == 'file' ) and os .path .exists (self ._root_path )
108
108
109
109
def get_document (self , doc_uri ):
110
- return self . _docs [ doc_uri ]
110
+ """Return a managed document if-present, else create one pointing at disk.
111
111
112
- def put_document ( self , doc_uri , content , version = None ):
113
- path = uris . to_fs_path ( doc_uri )
114
- self ._docs [ doc_uri ] = Document (
115
- doc_uri , content ,
116
- extra_sys_path = self . source_roots ( path ) , version = version , rope = self . _rope
117
- )
112
+ See https://github.com/Microsoft/language-server-protocol/issues/177
113
+ """
114
+ return self ._docs . get ( doc_uri ) or self . _create_document ( doc_uri )
115
+
116
+ def put_document ( self , doc_uri , source , version = None ):
117
+ self . _docs [ doc_uri ] = self . _create_document ( doc_uri , source = source , version = version )
118
118
119
119
def rm_document (self , doc_uri ):
120
120
self ._docs .pop (doc_uri )
@@ -140,6 +140,13 @@ def source_roots(self, document_path):
140
140
files = _utils .find_parents (self ._root_path , document_path , ['setup.py' ]) or []
141
141
return [os .path .dirname (setup_py ) for setup_py in files ]
142
142
143
+ def _create_document (self , doc_uri , source = None , version = None ):
144
+ path = uris .to_fs_path (doc_uri )
145
+ return Document (
146
+ doc_uri , source = source ,
147
+ extra_sys_path = self .source_roots (path ), rope = self ._rope , version = version
148
+ )
149
+
143
150
144
151
class Document (object ):
145
152
0 commit comments