Commits

SirAlaran committed 119a91e

Load completions without requiring a save. Remove debugging print statements.

Comments (0)

Files changed (1)

 		end
 	end
 
-	if buffer.filename == nil then return end
+	local codeFileName = os.tmpname() .. ".d"
+	local codeFile = io.open(codeFileName, "w")
+	codeFile:write(buffer:get_text())
+	codeFile:close()
 
-	local tmpFileName = os.tmpname()
-	local commandString = M.PATH_TO_DSCANNER .. " -l " .. buffer.filename .. " > " .. tmpFileName
+	local outputFileName = os.tmpname()
+	local commandString = M.PATH_TO_DSCANNER .. " -l "
+	if buffer.filename then
+		commandString = commandString .. "-I " .. buffer.filename:match("^.+/") .. " "
+	end
+	commandString = commandString .. codeFileName .. " > " .. outputFileName
 	os.execute(commandString)
-	pcallSucceeded, errorMessage = pcall(dofile, tmpFileName)
-	os.remove(tmpFileName)
+	pcallSucceeded, errorMessage = pcall(dofile, outputFileName)
+	os.remove(outputFileName)
+	os.remove(codeFileName)
 	if not pcallSucceeded then
 		gui.statusbar_text = "Could not load " .. buffer.filename
 		return
 	for _, directory in ipairs(dscannerOutput["importDirs"]) do
 		table.insert(completionInfo.importDirectories, directory)
 	end
-
-	gui.statusbar_text = "Loaded completions for " .. buffer.filename
 end
 
 events.connect(events.FILE_AFTER_SAVE, loadCompletionInfo)
 events.connect(events.BUFFER_AFTER_SWITCH, loadCompletionInfo)
 events.connect(events.VIEW_AFTER_SWITCH, loadCompletionInfo)
+timeout(5, function()
+	if buffer.dirty then
+		loadCompletionInfo()
+	end
+	return true
+end)
+
 
 -- Sorts the given completion options correctly based on autocompletion settings
 local function sortCompletions(completions)
 		table.remove(stack)
 	end
 	local part = table.concat(stack, "/") .. "/"
-	print("part is", part)
 	local completions = {}
 	for _, path in ipairs(completionInfo.importDirectories) do
 		local p = (path .. "/" .. part):match("^.+/")
-		print("searching for ", p)
 		if lfs.attributes(p, "mode") == "directory" then
-			print("It's a directory")
 			for child in lfs.dir(p) do
 				local mode = lfs.attributes(p .. "/" .. child, "mode")
-				print(child, "is a", mode)
 				if mode == "directory" then
 					if not child:match("^%.") then
 						completions[#completions + 1] = child .. "?3"
 		_M.textadept.editing.autocomplete_word("%w_")
 		return
 	end
-	print("symbol", symbol)
 	local before = symbol:match("^([^%.]+)")
 	local after = symbol:match("%.([^%.]+)")
-	print("before", before, "after", after)
 	local part = after
 	local container = before
 	if after == nil then