Skip to content

Commit

Permalink
Default to full document synchronization for now
Browse files Browse the repository at this point in the history
  • Loading branch information
hansec committed Nov 6, 2017
1 parent 811497a commit af367b8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Hover:

Diagnostics:

- Multiple use of the same variable name
- Unknown module in USE statement
- Variable masking definition from parent scope
- Multiple use of the same variable name
- Unknown module in USE statement
- Variable masking definition from parent scope

.. image:: https://raw.githubusercontent.com/hansec/fortran-language-server/master/images/fortls_diag.png

Expand Down
7 changes: 6 additions & 1 deletion fortls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def main():
'--symbol_skip_mem', action="store_true",
help="Do not include type members in document symbol results"
)
parser.add_argument(
'--incrmental_sync', action="store_true",
help="Use incremental document syncronization (beta)"
)
parser.add_argument(
'--debug_parser', action="store_true",
help="Test source parser on specified file instead of running language server"
Expand All @@ -40,7 +44,8 @@ def main():
debug_server = args.debug_symbols or (args.debug_rootpath is not None)
#
settings = {
"symbol_include_mem": (not args.symbol_skip_mem)
"symbol_include_mem": (not args.symbol_skip_mem),
"sync_type": 2 if args.incrmental_sync else 1
}
#
if args.debug_parser:
Expand Down
37 changes: 22 additions & 15 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,16 @@ def __init__(self, conn, logLevel=0, settings=None):
self.post_messages = []
self.streaming = True
self.symbol_include_mem = True
self.sync_type = 1
if logLevel == 0:
logging.basicConfig(level=logging.ERROR)
elif logLevel == 1:
logging.basicConfig(level=logging.DEBUG)
if settings is not None:
if "symbol_include_mem" in settings:
self.symbol_include_mem = settings["symbol_include_mem"]
if "sync_type" in settings:
self.sync_type = settings["sync_type"]

def run(self):
# Run server
Expand Down Expand Up @@ -420,7 +423,7 @@ def serve_initialize(self, request):
},
"definitionProvider": True,
"hoverProvider": True,
"textDocumentSync": 2
"textDocumentSync": self.sync_type
}
}
# "referencesProvider": True,
Expand Down Expand Up @@ -835,24 +838,28 @@ def serve_onChange(self, request):
uri = params["textDocument"]["uri"]
path = path_from_uri(uri)
# Update file with changes
if path in self.workspace:
new_contents = self.workspace[path]["contents"]
try:
for change in params["contentChanges"]:
old_contents = new_contents
new_contents, line_tmp = apply_change(old_contents, change)
except:
if self.sync_type == 1:
new_contents = params["contentChanges"][0]["text"].splitlines()
self.update_workspace_file(new_contents, path)
else:
if path in self.workspace:
new_contents = self.workspace[path]["contents"]
try:
for change in params["contentChanges"]:
old_contents = new_contents
new_contents, line_tmp = apply_change(old_contents, change)
except:
self.conn.send_notification("window/showMessage", {
"type": 1,
"message": 'Change request failed for unknown file "{0}"'.format(path)
})
else:
self.update_workspace_file(new_contents, path)
else:
self.conn.send_notification("window/showMessage", {
"type": 1,
"message": 'Change request failed for unknown file "{0}"'.format(path)
})
else:
self.update_workspace_file(new_contents, path)
else:
self.conn.send_notification("window/showMessage", {
"type": 1,
"message": 'Change request failed for unknown file "{0}"'.format(path)
})
# Update inheritance (currently only on open/save)
# for key in self.obj_tree:
# self.obj_tree[key][0].resolve_inherit(self.obj_tree)
Expand Down
2 changes: 1 addition & 1 deletion test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sys.path.insert(0, root_dir)
from fortls.jsonrpc import write_rpc_request, write_rpc_notification, read_rpc_messages

run_command = os.path.join(root_dir, "fortls.py --unbuffered")
run_command = os.path.join(root_dir, "fortls.py --unbuffered --incrmental_sync")
test_dir = os.path.join(root_dir, "test/test_source")


Expand Down

0 comments on commit af367b8

Please sign in to comment.